
/*jadclipse*/// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.

package com.kingdee.eas.scm.cal.app;

import com.kingdee.bos.BOSException;
import com.kingdee.bos.Context;
import com.kingdee.bos.dao.ormapping.ObjectUuidPK;
import com.kingdee.bos.util.BOSUuid;
import com.kingdee.eas.basedata.assistant.*;
import com.kingdee.eas.basedata.master.material.MaterialInfo;
import com.kingdee.eas.basedata.org.*;
import com.kingdee.eas.common.EASBizException;
import com.kingdee.eas.dynbusiness.util.DBUtil;
import com.kingdee.eas.framework.SystemEnum;
import com.kingdee.eas.framework.report.util.*;
import com.kingdee.eas.scm.cal.SumTypeEnum;
import com.kingdee.eas.scm.cal.VoucheredEnum;
import com.kingdee.eas.scm.cal.util.CalculateUtil;
import com.kingdee.eas.scm.common.BillBaseStatusEnum;
import com.kingdee.eas.scm.common.util.SCMUtils;
import java.util.Date;
import org.apache.log4j.Logger;

// Referenced classes of package com.kingdee.eas.scm.cal.app:
//            AbstractStockGatherReportFacadeControllerBean

public class StockGatherReportFacadeControllerBean extends AbstractStockGatherReportFacadeControllerBean
{

            public StockGatherReportFacadeControllerBean()
            {
/*  57*/        res = "com.kingdee.eas.scm.cal.CalRptResource";
            }

            protected RptParams _createTempTable(Context ctx, RptParams params)
                throws BOSException, EASBizException
            {
/*  64*/        dropTempTable(params.getString("tempTable"), ctx);
/*  66*/        String SumTypeFieldName = ((SumTypeEnum)params.getObject("sumType")).getValue().toString();
/*  69*/        int beginYear = params.getInt("accPeriodYearFrom");
/*  70*/        int beginPeriod = params.getInt("accPeriodMonthFrom");
/*  72*/        int beginOldYear = beginYear;
/*  73*/        int beginOldPeriod = beginPeriod;
/*  76*/        int endYear = params.getInt("accPeriodYearTo");
/*  77*/        int endPeriod = params.getInt("accPeriodMonthTo");
/*  78*/        int toPeriod = endYear * 100 + endPeriod;
/*  80*/        PeriodInfo currentPeriodInfo = SystemStatusCtrolUtils.getCurrentPeriod(ctx, SystemEnum.INVENTORYMANAGEMENT, (CompanyOrgUnitInfo)params.getObject("company"));
/*  83*/        int currentPeriod = currentPeriodInfo.getPeriodYear() * 100 + currentPeriodInfo.getPeriodNumber();
/*  86*/        PeriodInfo nextPeriodInfo = null;
/*  88*/        try
                {
/*  88*/            nextPeriodInfo = PeriodUtils.getNextPeriodInfo(ctx, currentPeriodInfo);
                }
/*  90*/        catch(BOSException be)
                {
/*  91*/            logger.info("next period is null ");
                }
/*  92*/        catch(EASBizException ee)
                {
/*  93*/            logger.info("next period is null ");
                }
/*  96*/        int nextPeriod = -1;
/*  97*/        if(nextPeriodInfo != null)
/*  98*/            nextPeriod = nextPeriodInfo.getPeriodYear() * 100 + nextPeriodInfo.getPeriodNumber();
/* 102*/        if(100 * beginYear + beginPeriod > currentPeriod)
                {
/* 103*/            beginYear = currentPeriodInfo.getPeriodYear();
/* 104*/            beginPeriod = currentPeriodInfo.getPeriodNumber();
/* 105*/            params.setInt("accPeriodYearFrom", beginYear);
/* 106*/            params.setInt("accPeriodMonthFrom", beginPeriod);
                }
/* 110*/        long lStart = 0L;
/* 110*/        long lEnd = 0L;
/* 111*/        String tempTable = DBUtil.createTempTable(ctx, getCreateTable(params));
/* 113*/        String wherePeriodSql = getWherePeriodSql(ctx, params, currentPeriodInfo, true);
/* 114*/        params.setString("wherePeriodSql", wherePeriodSql);
/* 115*/        if(toPeriod >= currentPeriodInfo.getNumber())
                {
/* 116*/            params.setBoolean("hasCurrAndAfterPeriod", true);
/* 117*/            wherePeriodSql = getWherePeriodSql(ctx, params, currentPeriodInfo, false);
/* 118*/            params.setString("whereCurrAndAfterPeriodSql", wherePeriodSql);
                }
/* 122*/        lStart = GetNowTime();
/* 123*/        String sql = getPeriodHappen(ctx, tempTable, params);
/* 124*/        executeSQL(ctx, sql);
/* 125*/        lEnd = GetNowTime();
/* 126*/        logger.info("StockGatherReporter get period happen data spend time:" + String.valueOf(lEnd - lStart));
/* 130*/        if(toPeriod > currentPeriod && nextPeriodInfo != null)
                {
/* 131*/            sql = getInsertNextPeriod(ctx, tempTable, currentPeriodInfo, nextPeriodInfo);
/* 132*/            executeSQL(ctx, sql);
                }
/* 135*/        if(toPeriod > nextPeriod && nextPeriod != -1)
                {
/* 136*/            PeriodInfo next2PeriodInfo = null;
/* 138*/            try
                    {
/* 138*/                next2PeriodInfo = PeriodUtils.getNextPeriodInfo(ctx, nextPeriodInfo);
                    }
/* 139*/            catch(Exception e)
                    {
/* 140*/                logger.info("Get next period exception:" + e);
                    }
/* 142*/            if(next2PeriodInfo != null)
                    {
/* 143*/                sql = getInsertNextPeriod(ctx, tempTable, nextPeriodInfo, next2PeriodInfo);
/* 144*/                executeSQL(ctx, sql);
                    }
                }
/* 149*/        if(toPeriod >= currentPeriod)
                {
/* 150*/            sql = updatePeriodLast(ctx, tempTable, currentPeriodInfo.getPeriodYear(), currentPeriodInfo.getPeriodNumber());
/* 152*/            executeSQL(ctx, sql);
                }
/* 155*/        if(toPeriod >= nextPeriod && nextPeriod != -1)
                {
/* 157*/            sql = updatePeriodFirst(ctx, tempTable, currentPeriodInfo.getPeriodYear(), currentPeriodInfo.getPeriodNumber(), nextPeriodInfo.getPeriodYear(), nextPeriodInfo.getPeriodNumber());
/* 161*/            executeSQL(ctx, sql);
/* 164*/            sql = updatePeriodLast(ctx, tempTable, nextPeriodInfo.getPeriodYear(), nextPeriodInfo.getPeriodNumber());
/* 166*/            executeSQL(ctx, sql);
                }
/* 168*/        if(params.getBoolean("NoInOrOutNoShow"))
                {
/* 169*/            sql = "delete from " + tempTable + " where FInQty=0 and FOutQty=0 and FINAMOUNT=0 and FOUTAMOUNT=0";
/* 170*/            executeSQL(ctx, sql);
                }
/* 172*/        int balanceCondition = params.getInt("ShowBalanceCondition");
/* 173*/        switch(balanceCondition)
                {
/* 175*/        case 1: // '\001'
/* 175*/            sql = "delete from " + tempTable + " where FRemainQty <> 0";
                    break;

/* 178*/        case 2: // '\002'
/* 178*/            sql = "delete from " + tempTable + " where FRemainQty = 0";
                    break;

/* 181*/        case 3: // '\003'
/* 181*/            sql = "delete from " + tempTable + " where FRemainQty <= 0";
                    break;

/* 184*/        case 4: // '\004'
/* 184*/            sql = "delete from " + tempTable + " where FRemainQty >= 0";
                    break;

/* 187*/        default:
/* 187*/            sql = null;
                    break;
                }
/* 189*/        if(sql != null)
/* 190*/            executeSQL(ctx, sql);
/* 193*/        sql = getPeriodHappenTotal(ctx, tempTable, params);
/* 194*/        executeSQL(ctx, sql);
/* 197*/        sql = getPeriodTotal(ctx, tempTable, SumTypeFieldName);
/* 198*/        executeSQL(ctx, sql);
/* 201*/        getYearTotal(ctx, tempTable, beginYear, beginPeriod, endYear, endPeriod, SumTypeFieldName);
/* 204*/        getAllTotal(ctx, tempTable, beginYear, beginPeriod, SumTypeFieldName);
/* 207*/        sql = "Update " + tempTable + " Set FYear=null Where FYear=0 ";
/* 208*/        executeSQL(ctx, sql);
/* 209*/        sql = "Update " + tempTable + " Set FPeriod=null Where FPeriod=0 ";
/* 210*/        executeSQL(ctx, sql);
/* 211*/        if(SumTypeFieldName.equals("FCalculateType"))
/* 212*/            sql = "Update " + tempTable + " Set FSUMTYPEID=null Where FSUMTYPEID=0 ";
/* 214*/        else
/* 214*/            sql = "Update " + tempTable + " Set FSUMTYPEID=null Where FSUMTYPEID in('',' ')";
/* 216*/        executeSQL(ctx, sql);
/* 219*/        if(100 * beginOldYear + beginOldPeriod > currentPeriod)
                {
/* 220*/            sql = "delete from " + tempTable + " where 100*fyear + fperiod < " + (100 * beginOldYear + beginOldPeriod);
/* 221*/            executeSQL(ctx, sql);
                }
/* 223*/        if(SumTypeFieldName.equals("FMaterialGroupLevel"))
                {
/* 226*/            sql = "update " + tempTable + " as  t2 set FSumTypeName=";
/* 227*/            sql = sql + "(select t3.flongnumber from t_bd_material t1,t_bd_materialgroup t3 where  t2.fmaterialid=t1.fid and t3.fid=t1.fmaterialgroupid) where findex=0";
/* 228*/            executeSQL(ctx, sql);
/* 230*/            sql = "update " + tempTable + " as  t2 set FMATERIALGROUPID1=";
/* 231*/            sql = sql + "(select CASE CHARINDEX('!', t3.flongnumber) WHEN 0 THEN t3.flongnumber ELSE LEFT(t3.flongnumber,CHARINDEX('!', t3.flongnumber)-1) END from t_bd_material t1,t_bd_materialgroup t3 where  t2.fmaterialid=t1.fid and t3.fid=t1.fmaterialgroupid) ";
/* 232*/            executeSQL(ctx, sql);
/* 234*/            sql = "update " + tempTable + " as  t1 set FMATERIALGROUPNAME1=";
/* 235*/            sql = sql + "(select t2.fname_" + getLoc(ctx) + " from t_bd_materialgroup t2 where t1.FMATERIALGROUPID1=t2.flongnumber) ";
/* 236*/            executeSQL(ctx, sql);
/* 239*/            int materialGroupLevel = params.getInt("materialGroupLevel");
/* 240*/            for(int i = 2; i <= materialGroupLevel; i++)
                    {
/* 242*/                sql = "update " + tempTable + " set FMATERIALGROUPID" + i + "=CASE LENGTH(FSumTypeName)-LENGTH(FMATERIALGROUPID" + (i - 1) + "||'') when 0 then '' when -1 then '' else SUBSTRING(FSumTypeName,length(FMATERIALGROUPID" + (i - 1) + ")+2,length(FSumTypeName)-length(FMATERIALGROUPID" + (i - 1) + ")) END";
/* 243*/                executeSQL(ctx, sql);
/* 244*/                sql = "update " + tempTable + " set FMATERIALGROUPID" + i + "=CASE CHARINDEX('!', FMATERIALGROUPID" + i + " ) WHEN 0 THEN FMATERIALGROUPID" + i + "  ELSE LEFT(FMATERIALGROUPID" + i + " ,CHARINDEX('!',FMATERIALGROUPID" + i + " )-1) END";
/* 245*/                executeSQL(ctx, sql);
/* 246*/                sql = "update " + tempTable + " set FMATERIALGROUPID" + i + "=case  FMATERIALGROUPID" + i + " WHEN '' then '' else FMATERIALGROUPID" + (i - 1) + "||'!'||FMATERIALGROUPID" + i + " END";
/* 247*/                executeSQL(ctx, sql);
/* 249*/                sql = "update " + tempTable + " as  t1 set FMATERIALGROUPNAME" + i;
/* 250*/                sql = sql + "=(select t2.fname_" + getLoc(ctx) + " from t_bd_materialgroup t2 where t1.FMATERIALGROUPID" + i + "=t2.flongnumber) ";
/* 251*/                executeSQL(ctx, sql);
                    }

/* 253*/            sql = "delete from " + tempTable + " where findex=1";
/* 254*/            executeSQL(ctx, sql);
/* 255*/            sql = "update  " + tempTable + " set FMATERIALGROUPNAME1=fsumtypename where findex<>0";
/* 256*/            executeSQL(ctx, sql);
/* 257*/            StringBuffer sqlbuff = new StringBuffer();
/* 258*/            for(int i = 1; i <= materialGroupLevel; i++)
                    {
/* 260*/                sqlbuff.setLength(0);
/* 261*/                sqlbuff.append("Insert Into " + tempTable + "(FINDEX,FCompanyOrgUnitID,FCOMPANYNAME,FYear,FPeriod,FMaterialID ,FMATERIALNAME ,FMaterialNumber ,FMaterialModel,FBASEUNITNAME,FSUMTYPEID ,FSUMTYPENAME ,FBEGINQTY ,FBEGINAMOUNT   ,FINQTY  ,FINAMOUNT ,FOUTQTY  ,FOUTAMOUNT ,FREMAINQTY ,FREMAINAMOUNT");
/* 262*/                for(int j = 1; j <= i; j++)
/* 264*/                    sqlbuff.append(",FMATERIALGROUPID" + j + ",FMATERIALGROUPNAME" + j);

/* 267*/                sqlbuff.append(")\r\n");
/* 268*/                sqlbuff.append(" Select 0.5 as FIndex,FCompanyOrgUnitID as FCompanyOrgUnitID,FCOMPANYNAME as FCompanyName,\r\n");
/* 270*/                sqlbuff.append("FYear,FPeriod,\r\n");
/* 271*/                sqlbuff.append("' ' as FMaterialID,' ' as FMaterialName,\r\n");
/* 272*/                sqlbuff.append("' ' as FMaterialNumber,' ' as FMaterialModel,");
/* 273*/                sqlbuff.append("' ' as FBaseUnitName,\r\n");
/* 274*/                if(SumTypeFieldName.equals("FCalculateType"))
/* 275*/                    sqlbuff.append("0 as FSumTypeID, ");
/* 277*/                else
/* 277*/                    sqlbuff.append("' ' as FSumTypeID, ");
/* 279*/                sqlbuff.append("'' FSumTypeName,\r\n");
/* 281*/                sqlbuff.append("sum(FBeginQty) as FBeginQty,sum(FBeginAmount) as FBeginAmount,\r\n");
/* 283*/                sqlbuff.append("sum(FInQty) as FInQty,Sum(FInAmount)as FInAmount,\r\n");
/* 285*/                sqlbuff.append("Sum(FOutQty) as FOutQty,Sum(FOutAmount) as FOutAmount,\r\n");
/* 287*/                sqlbuff.append("sum(FRemainQty) as FRemainQty,sum(FRemainAmount) as FRemainAmount \r\n");
/* 289*/                for(int j = 1; j <= i; j++)
/* 291*/                    sqlbuff.append(",FMATERIALGROUPID" + j + ",FMATERIALGROUPNAME" + j);

/* 293*/                sqlbuff.append("||'").append(SCMUtils.getResource(res, "TOTAL", ctx));
/* 294*/                sqlbuff.append("' From " + tempTable + "\r\n");
/* 295*/                sqlbuff.append("Where FIndex=0 \r\n");
/* 296*/                sqlbuff.append(" and length(FMATERIALGROUPNAME").append(i).append(")>0 ");
/* 297*/                sqlbuff.append("Group By FCompanyOrgUnitID,FCOMPANYNAME,FYear,FPeriod \r\n");
/* 298*/                for(int j = 1; j <= i; j++)
/* 300*/                    sqlbuff.append(",FMATERIALGROUPID" + j + ",FMATERIALGROUPNAME" + j);

/* 303*/                executeSQL(ctx, sqlbuff.toString());
                    }

                }
/* 307*/        params.setInt("accPeriodYearFrom", beginOldYear);
/* 308*/        params.setInt("accPeriodMonthTo", beginOldPeriod);
/* 311*/        RptTableHeader header1 = createTableHeader(ctx, params);
/* 313*/        RptParams result = new RptParams();
/* 314*/        result.setString("tempTable", tempTable);
/* 315*/        result.setObject("header", header1);
/* 316*/        return result;
            }

            private RptTableHeader createTableHeader(Context ctx, RptParams params)
                throws BOSException, EASBizException
            {
/* 329*/        CompanyOrgUnitInfo aCompanyOrgUnitInfo = (CompanyOrgUnitInfo)params.getObject("company");
/* 330*/        int amtPrecision = CalculateUtil.getLocalCurrencyPrecision(ctx, aCompanyOrgUnitInfo);
/* 331*/        String amtFormat = CalculateUtil.getFormatPattern(amtPrecision);
/* 332*/        String prcFormat = CalculateUtil.getFormatPattern(6);
/* 333*/        String qtyFormat = CalculateUtil.getFormatPattern(4);
/* 334*/        String SumTypeFieldName = ((SumTypeEnum)params.getObject("sumType")).getValue().toString();
/* 336*/        RptTableHeader header = new RptTableHeader();
/* 337*/        RptTableColumn col = null;
/* 340*/        col = new RptTableColumn("FCompanyName");
/* 341*/        col.setWidth(150);
/* 342*/        header.addColumn(col);
/* 345*/        col = new RptTableColumn("FYear");
/* 346*/        col.setWidth(50);
/* 347*/        header.addColumn(col);
/* 349*/        col = new RptTableColumn("FPeriod");
/* 350*/        col.setWidth(50);
/* 351*/        header.addColumn(col);
/* 355*/        col = new RptTableColumn("FSumTypeName");
/* 356*/        col.setWidth(100);
/* 358*/        if(!((SumTypeEnum)params.getObject("sumType")).getValue().equals("FMaterialGroupLevel"))
/* 360*/            header.addColumn(col);
/* 363*/        if(SumTypeFieldName.equals("FMaterialGroupLevel"))
                {
/* 365*/            int materialGroupLevel = params.getInt("materialGroupLevel");
/* 366*/            for(int i = 1; i <= materialGroupLevel; i++)
                    {
/* 368*/                col = new RptTableColumn("FMATERIALGROUPNAME" + i);
/* 369*/                col.setWidth(100);
/* 370*/                header.addColumn(col);
                    }

                }
/* 374*/        col = new RptTableColumn("FMaterialNumber");
/* 375*/        col.setFormatPattern("@");
/* 376*/        col.setWidth(100);
/* 377*/        col.setHided(params.getBoolean("onlyViewSumRow"));
/* 378*/        header.addColumn(col);
/* 380*/        col = new RptTableColumn("FMATERIALNAME");
/* 381*/        col.setWidth(150);
/* 382*/        col.setHided(params.getBoolean("onlyViewSumRow"));
/* 383*/        header.addColumn(col);
/* 385*/        col = new RptTableColumn("FSHORTNAME");
/* 386*/        col.setWidth(150);
/* 387*/        if(params.getBoolean("onlyViewSumRow"))
/* 388*/            col.setHided(true);
/* 390*/        else
/* 390*/        if(params.getObject("ckBxMShortName") != null && params.getBoolean("ckBxMShortName"))
/* 391*/            col.setHided(false);
/* 393*/        else
/* 393*/            col.setHided(true);
/* 395*/        header.addColumn(col);
/* 397*/        col = new RptTableColumn("FMaterialModel");
/* 398*/        col.setWidth(100);
/* 399*/        col.setHided(params.getBoolean("onlyViewSumRow"));
/* 400*/        header.addColumn(col);
/* 402*/        col = new RptTableColumn("FBASEUNITNAME");
/* 403*/        col.setWidth(100);
/* 404*/        col.setHided(params.getBoolean("onlyViewSumRow"));
/* 405*/        header.addColumn(col);
/* 409*/        col = new RptTableColumn("FBeginQTY");
/* 410*/        col.setWidth(80);
/* 411*/        col.setAligment(2);
/* 412*/        col.setFormatPattern(qtyFormat);
/* 413*/        header.addColumn(col);
/* 415*/        col = new RptTableColumn("FBeginPrice");
/* 416*/        col.setWidth(80);
/* 417*/        col.setAligment(2);
/* 418*/        col.setFormatPattern(prcFormat);
/* 419*/        header.addColumn(col);
/* 421*/        col = new RptTableColumn("FBeginAmount");
/* 422*/        col.setWidth(100);
/* 423*/        col.setAligment(2);
/* 424*/        col.setFormatPattern(amtFormat);
/* 425*/        header.addColumn(col);
/* 429*/        col = new RptTableColumn("FInQTY");
/* 430*/        col.setWidth(80);
/* 431*/        col.setAligment(2);
/* 432*/        col.setFormatPattern(prcFormat);
/* 434*/        String qtyFormat2 = RptCellFormatter.getNumberFormat(4, true);
/* 435*/        col.setFormatPattern(qtyFormat2);
/* 436*/        header.addColumn(col);
/* 438*/        col = new RptTableColumn("FInPrice");
/* 439*/        col.setWidth(80);
/* 440*/        col.setAligment(2);
/* 441*/        col.setFormatPattern(prcFormat);
/* 442*/        header.addColumn(col);
/* 444*/        col = new RptTableColumn("FInAmount");
/* 445*/        col.setWidth(100);
/* 446*/        col.setAligment(2);
/* 447*/        col.setFormatPattern(amtFormat);
/* 448*/        header.addColumn(col);
/* 452*/        col = new RptTableColumn("FOutQTY");
/* 453*/        col.setWidth(80);
/* 454*/        col.setAligment(2);
/* 455*/        col.setFormatPattern(qtyFormat);
/* 456*/        header.addColumn(col);
/* 458*/        col = new RptTableColumn("FOutPrice");
/* 459*/        col.setWidth(80);
/* 460*/        col.setAligment(2);
/* 461*/        col.setFormatPattern(prcFormat);
/* 462*/        header.addColumn(col);
/* 464*/        col = new RptTableColumn("FOutAmount");
/* 465*/        col.setWidth(100);
/* 466*/        col.setAligment(2);
/* 467*/        col.setFormatPattern(amtFormat);
/* 468*/        header.addColumn(col);
/* 472*/        col = new RptTableColumn("FRemainQTY");
/* 473*/        col.setWidth(80);
/* 474*/        col.setAligment(2);
/* 475*/        col.setFormatPattern(qtyFormat);
/* 476*/        header.addColumn(col);
/* 478*/        col = new RptTableColumn("FRemainPrice");
/* 479*/        col.setWidth(80);
/* 480*/        col.setAligment(2);
/* 481*/        col.setFormatPattern(prcFormat);
/* 482*/        header.addColumn(col);
/* 484*/        col = new RptTableColumn("FRemainAmount");
/* 485*/        col.setWidth(100);
/* 486*/        col.setAligment(2);
/* 487*/        col.setFormatPattern(amtFormat);
/* 488*/        header.addColumn(col);
/* 491*/        col = new RptTableColumn("FSumTypeID");
/* 492*/        col.setWidth(0);
/* 493*/        col.setHided(true);
/* 494*/        header.addColumn(col);
/* 497*/        col = new RptTableColumn("FMaterialID");
/* 498*/        col.setWidth(0);
/* 499*/        col.setHided(true);
/* 500*/        header.addColumn(col);
/* 503*/        col = new RptTableColumn("FIndex");
/* 504*/        col.setWidth(0);
/* 505*/        col.setHided(true);
/* 506*/        header.addColumn(col);
/* 509*/        col = new RptTableColumn("FCompanyOrgUnitID");
/* 510*/        col.setWidth(0);
/* 511*/        col.setHided(true);
/* 512*/        header.addColumn(col);
/* 514*/        String intFormat = CalculateUtil.getFormatPattern(0);
/* 516*/        col = new RptTableColumn("fqtyprecision");
/* 517*/        col.setWidth(0);
/* 518*/        col.setHided(true);
/* 519*/        col.setFormatPattern(intFormat);
/* 520*/        header.addColumn(col);
/* 523*/        col = new RptTableColumn("fpriceprecision");
/* 524*/        col.setWidth(0);
/* 525*/        col.setHided(true);
/* 526*/        col.setFormatPattern(intFormat);
/* 527*/        header.addColumn(col);
/* 529*/        SumTypeFieldName = ((SumTypeEnum)params.getObject("sumType")).getAlias(ctx.getLocale());
/* 532*/        if(((SumTypeEnum)params.getObject("sumType")).getValue().equals("FMaterialGroupLevel"))
                {
/* 534*/            int materialGroupLevel = params.getInt("materialGroupLevel");
/* 535*/            Object aObject[][] = new Object[2][materialGroupLevel + 26];
/* 536*/            aObject[0][0] = SCMUtils.getResource(res, "FICU", ctx);
/* 537*/            aObject[0][1] = SCMUtils.getResource(res, "YEAR", ctx);
/* 538*/            aObject[0][2] = SCMUtils.getResource(res, "PERIOD", ctx);
/* 539*/            aObject[0][3] = SumTypeFieldName;
/* 540*/            aObject[1][0] = SCMUtils.getResource(res, "FICU", ctx);
/* 541*/            aObject[1][1] = SCMUtils.getResource(res, "YEAR", ctx);
/* 542*/            aObject[1][2] = SCMUtils.getResource(res, "PERIOD", ctx);
/* 543*/            for(int i = 1; i <= materialGroupLevel; i++)
                    {
/* 545*/                aObject[0][2 + i] = i + SCMUtils.getResource(res, "MATERIALGROUPLEVEL", ctx);
/* 546*/                aObject[1][2 + i] = i + SCMUtils.getResource(res, "MATERIALGROUPLEVEL", ctx);
                    }

/* 549*/            aObject[0][3 + materialGroupLevel++] = SCMUtils.getResource(res, "MATERIELCODE", ctx);
/* 550*/            aObject[0][3 + materialGroupLevel++] = SCMUtils.getResource(res, "MATERIELNAME", ctx);
/* 551*/            aObject[0][3 + materialGroupLevel++] = SCMUtils.getResource(res, "FSHORTNAME", ctx);
/* 552*/            aObject[0][3 + materialGroupLevel++] = SCMUtils.getResource(res, "MODEL", ctx);
/* 553*/            aObject[0][3 + materialGroupLevel++] = SCMUtils.getResource(res, "MEASUREUNIT", ctx);
/* 554*/            aObject[0][3 + materialGroupLevel++] = SCMUtils.getResource(res, "FIRSTPERIOD", ctx);
/* 555*/            aObject[0][3 + materialGroupLevel++] = SCMUtils.getResource(res, "FIRSTPERIOD", ctx);
/* 556*/            aObject[0][3 + materialGroupLevel++] = SCMUtils.getResource(res, "FIRSTPERIOD", ctx);
/* 557*/            aObject[0][3 + materialGroupLevel++] = SCMUtils.getResource(res, "IN", ctx);
/* 558*/            aObject[0][3 + materialGroupLevel++] = SCMUtils.getResource(res, "IN", ctx);
/* 559*/            aObject[0][3 + materialGroupLevel++] = SCMUtils.getResource(res, "IN", ctx);
/* 560*/            aObject[0][3 + materialGroupLevel++] = SCMUtils.getResource(res, "OUT", ctx);
/* 561*/            aObject[0][3 + materialGroupLevel++] = SCMUtils.getResource(res, "OUT", ctx);
/* 562*/            aObject[0][3 + materialGroupLevel++] = SCMUtils.getResource(res, "OUT", ctx);
/* 563*/            aObject[0][3 + materialGroupLevel++] = SCMUtils.getResource(res, "BALANCE", ctx);
/* 564*/            aObject[0][3 + materialGroupLevel++] = SCMUtils.getResource(res, "BALANCE", ctx);
/* 565*/            aObject[0][3 + materialGroupLevel++] = SCMUtils.getResource(res, "BALANCE", ctx);
/* 567*/            aObject[0][3 + materialGroupLevel++] = "FSumTypeID";
/* 568*/            aObject[0][3 + materialGroupLevel++] = "FMaterialID";
/* 569*/            aObject[0][3 + materialGroupLevel++] = "FIndex";
/* 570*/            aObject[0][3 + materialGroupLevel++] = "FCompanyOrgUnitID";
/* 571*/            aObject[0][3 + materialGroupLevel++] = "fqtyprecision";
/* 572*/            aObject[0][3 + materialGroupLevel++] = "fpriceprecision";
/* 574*/            materialGroupLevel = params.getInt("materialGroupLevel");
/* 575*/            aObject[1][3 + materialGroupLevel++] = SCMUtils.getResource(res, "MATERIELCODE", ctx);
/* 576*/            aObject[1][3 + materialGroupLevel++] = SCMUtils.getResource(res, "MATERIELNAME", ctx);
/* 577*/            aObject[1][3 + materialGroupLevel++] = SCMUtils.getResource(res, "FSHORTNAME", ctx);
/* 578*/            aObject[1][3 + materialGroupLevel++] = SCMUtils.getResource(res, "MODEL", ctx);
/* 579*/            aObject[1][3 + materialGroupLevel++] = SCMUtils.getResource(res, "MEASUREUNIT", ctx);
/* 580*/            aObject[1][3 + materialGroupLevel++] = SCMUtils.getResource(res, "QUANTITY", ctx);
/* 581*/            aObject[1][3 + materialGroupLevel++] = SCMUtils.getResource(res, "PRICE", ctx);
/* 582*/            aObject[1][3 + materialGroupLevel++] = SCMUtils.getResource(res, "AMOUNT", ctx);
/* 583*/            aObject[1][3 + materialGroupLevel++] = SCMUtils.getResource(res, "QUANTITY", ctx);
/* 584*/            aObject[1][3 + materialGroupLevel++] = SCMUtils.getResource(res, "PRICE", ctx);
/* 585*/            aObject[1][3 + materialGroupLevel++] = SCMUtils.getResource(res, "AMOUNT", ctx);
/* 586*/            aObject[1][3 + materialGroupLevel++] = SCMUtils.getResource(res, "QUANTITY", ctx);
/* 587*/            aObject[1][3 + materialGroupLevel++] = SCMUtils.getResource(res, "PRICE", ctx);
/* 588*/            aObject[1][3 + materialGroupLevel++] = SCMUtils.getResource(res, "AMOUNT", ctx);
/* 589*/            aObject[1][3 + materialGroupLevel++] = SCMUtils.getResource(res, "QUANTITY", ctx);
/* 590*/            aObject[1][3 + materialGroupLevel++] = SCMUtils.getResource(res, "PRICE", ctx);
/* 591*/            aObject[1][3 + materialGroupLevel++] = SCMUtils.getResource(res, "AMOUNT", ctx);
/* 593*/            aObject[1][3 + materialGroupLevel++] = "FSumTypeID";
/* 594*/            aObject[1][3 + materialGroupLevel++] = "FMaterialID";
/* 595*/            aObject[1][3 + materialGroupLevel++] = "FIndex";
/* 596*/            aObject[1][3 + materialGroupLevel++] = "FCompanyOrgUnitID";
/* 597*/            aObject[1][3 + materialGroupLevel++] = "fqtyprecision";
/* 598*/            aObject[1][3 + materialGroupLevel++] = "fpriceprecision";
/* 599*/            header.setLabels(aObject, true);
                } else
                {
/* 601*/            header.setLabels(new Object[][] {
/* 601*/                new Object[] {
/* 601*/                    SCMUtils.getResource(res, "FICU", ctx), SCMUtils.getResource(res, "YEAR", ctx), SCMUtils.getResource(res, "PERIOD", ctx), SumTypeFieldName, SCMUtils.getResource(res, "MATERIELCODE", ctx), SCMUtils.getResource(res, "MATERIELNAME", ctx), SCMUtils.getResource(res, "FSHORTNAME", ctx), SCMUtils.getResource(res, "MODEL", ctx), SCMUtils.getResource(res, "MEASUREUNIT", ctx), SCMUtils.getResource(res, "FIRSTPERIOD", ctx), 
/* 601*/                    SCMUtils.getResource(res, "FIRSTPERIOD", ctx), SCMUtils.getResource(res, "FIRSTPERIOD", ctx), SCMUtils.getResource(res, "IN", ctx), SCMUtils.getResource(res, "IN", ctx), SCMUtils.getResource(res, "IN", ctx), SCMUtils.getResource(res, "OUT", ctx), SCMUtils.getResource(res, "OUT", ctx), SCMUtils.getResource(res, "OUT", ctx), SCMUtils.getResource(res, "BALANCE", ctx), SCMUtils.getResource(res, "BALANCE", ctx), 
/* 601*/                    SCMUtils.getResource(res, "BALANCE", ctx), "FSumTypeID", "FMaterialID", "FIndex", "FCompanyOrgUnitID", "fqtyprecision", "fpriceprecision"
                        }, new Object[] {
/* 601*/                    SCMUtils.getResource(res, "FICU", ctx), SCMUtils.getResource(res, "YEAR", ctx), SCMUtils.getResource(res, "PERIOD", ctx), SumTypeFieldName, SCMUtils.getResource(res, "MATERIELCODE", ctx), SCMUtils.getResource(res, "MATERIELNAME", ctx), SCMUtils.getResource(res, "FSHORTNAME", ctx), SCMUtils.getResource(res, "MODEL", ctx), SCMUtils.getResource(res, "MEASUREUNIT", ctx), SCMUtils.getResource(res, "QUANTITY", ctx), 
/* 601*/                    SCMUtils.getResource(res, "PRICE", ctx), SCMUtils.getResource(res, "AMOUNT", ctx), SCMUtils.getResource(res, "QUANTITY", ctx), SCMUtils.getResource(res, "PRICE", ctx), SCMUtils.getResource(res, "AMOUNT", ctx), SCMUtils.getResource(res, "QUANTITY", ctx), SCMUtils.getResource(res, "PRICE", ctx), SCMUtils.getResource(res, "AMOUNT", ctx), SCMUtils.getResource(res, "QUANTITY", ctx), SCMUtils.getResource(res, "PRICE", ctx), 
/* 601*/                    SCMUtils.getResource(res, "AMOUNT", ctx), "FSumTypeID", "FMaterialID", "FIndex", "FCompanyOrgUnitID", "fqtyprecision", "fpriceprecision"
                        }
                    }, true);
                }
/* 650*/        return header;
            }

            private String getWherePeriodSql(Context ctx, RptParams params, PeriodInfo currPeriodInfo, boolean isAllPeriod)
                throws BOSException, EASBizException
            {
/* 657*/        CompanyOrgUnitInfo companyInfo = (CompanyOrgUnitInfo)params.getObject("company");
/* 658*/        if(companyInfo == null)
/* 659*/            throw new PeriodException(PeriodException.COMPANY_NOT_NULL);
/* 661*/        if(companyInfo.getAccountPeriodType() == null || companyInfo.getAccountPeriodType().getId() == null)
                {
/* 663*/            ICompanyOrgUnit iCompanyOrgUnit = null;
/* 664*/            iCompanyOrgUnit = CompanyOrgUnitFactory.getLocalInstance(ctx);
/* 665*/            companyInfo = iCompanyOrgUnit.getCompanyOrgUnitInfo(new ObjectUuidPK(companyInfo.getId()));
                }
/* 669*/        if(companyInfo.getAccountPeriodType() == null)
/* 670*/            return null;
/* 674*/        int beginYear = params.getInt("accPeriodYearFrom");
/* 675*/        int beginPeriod = params.getInt("accPeriodMonthFrom");
/* 677*/        int endYear = params.getInt("accPeriodYearTo");
/* 678*/        int endPeriod = params.getInt("accPeriodMonthTo");
/* 679*/        if(!isAllPeriod)
                {
/* 680*/            beginYear = currPeriodInfo.getPeriodYear();
/* 681*/            beginPeriod = currPeriodInfo.getPeriodNumber();
                }
/* 683*/        int fromPeriod = beginYear * 100 + beginPeriod;
/* 684*/        int toPeriod = endYear * 100 + endPeriod;
/* 686*/        StringBuffer wherePeriod = new StringBuffer();
/* 687*/        if(fromPeriod == toPeriod)
/* 688*/            wherePeriod.append("(h.fyear = ").append(beginYear).append(" and h.fperiod = ").append(beginPeriod).append(")");
/* 691*/        else
/* 691*/            wherePeriod.append("(h.FYear * 100 + h.FPeriod >=").append(fromPeriod).append(" and h.FYear * 100 + h.FPeriod <=").append(toPeriod).append(")");
/* 693*/        return wherePeriod.toString();
            }

            private long GetNowTime()
            {
/* 697*/        Date d = new Date();
/* 698*/        return d.getTime();
            }

            private String getCreateTable(RptParams params)
            {
/* 708*/        StringBuffer sql = new StringBuffer();
/* 710*/        String SumTypeFieldName = null;
/* 711*/        if(params.getObject("sumType") != null)
/* 712*/            SumTypeFieldName = ((SumTypeEnum)params.getObject("sumType")).getValue().toString();
/* 716*/        String SumTypeFieldType = null;
/* 717*/        if(params.getObject("sumType") != null)
/* 718*/            if(SumTypeFieldName.equals("FCalculateType"))
/* 719*/                SumTypeFieldType = " int,";
/* 721*/            else
/* 721*/                SumTypeFieldType = " Varchar(44),";
/* 726*/        sql.append("Create Table TempReportTable \r\n");
/* 727*/        sql.append("(FINDEX Int NOT NULL , \r\n");
/* 728*/        sql.append("FCompanyOrgUnitID Varchar(44), \r\n");
/* 729*/        sql.append("FCOMPANYNAME NVarchar(100), \r\n");
/* 730*/        sql.append("FYear int, \r\n");
/* 731*/        sql.append("FPeriod int, \r\n");
/* 732*/        sql.append("FMaterialID Varchar(44), \r\n");
/* 733*/        sql.append("FMATERIALNAME NVarchar(200),\r\n");
/* 734*/        sql.append("FMaterialNumber NVarchar(100),\r\n");
/* 735*/        sql.append("FSHORTNAME NVarchar(200),\r\n");
/* 736*/        sql.append("FMaterialModel NVarchar(100),\r\n");
/* 737*/        sql.append("FBASEUNITNAME NVarchar(100),\r\n");
/* 739*/        sql.append("FSUMTYPEID " + SumTypeFieldType + "\r\n");
/* 740*/        sql.append("FSUMTYPENAME Varchar(100),\r\n");
/* 742*/        if(SumTypeFieldName.equals("FMaterialGroupLevel"))
                {
/* 744*/            int materialGroupLevel = params.getInt("materialGroupLevel");
/* 745*/            for(int i = 1; i <= materialGroupLevel; i++)
                    {
/* 747*/                sql.append("FMATERIALGROUPID" + i + " Varchar(100),\r\n");
/* 748*/                sql.append("FMATERIALGROUPNAME" + i + " Varchar(100),\r\n");
                    }

                }
/* 752*/        sql.append("FBEGINQTY NUMERIC(21, 8) ,\r\n");
/* 753*/        sql.append("FBEGINAMOUNT NUMERIC(17, 4)  ,\r\n");
/* 755*/        sql.append("FINQTY NUMERIC(21, 8) ,\r\n");
/* 756*/        sql.append("FINAMOUNT NUMERIC(17, 4)  ,\r\n");
/* 758*/        sql.append("FOUTQTY NUMERIC(21, 8) ,\r\n");
/* 759*/        sql.append("FOUTAMOUNT NUMERIC(17, 4)  ,\r\n");
/* 761*/        sql.append("FREMAINQTY NUMERIC(21, 8)  ,\r\n");
/* 762*/        sql.append("FREMAINAMOUNT NUMERIC(17, 4) );\r\n");
/* 764*/        return sql.toString();
            }

            private String getPeriodHappen(Context ctx, String tempTable, RptParams params)
                throws BOSException, EASBizException
            {
/* 773*/        StringBuffer sqlAll = new StringBuffer();
/* 774*/        sqlAll.append("INSERT INTO " + tempTable + "(FINDEX,FCompanyOrgUnitID,FCOMPANYNAME,FYear,FPeriod,FMaterialID,FMATERIALNAME,").append("\r\n");
/* 775*/        sqlAll.append("FMaterialNumber,FSHORTNAME,FMaterialModel,FBASEUNITNAME,FSUMTYPEID,FSUMTYPENAME,FBEGINQTY,FBEGINAMOUNT,FINQTY,").append("\r\n");
/* 776*/        sqlAll.append("FINAMOUNT,FOUTQTY,FOUTAMOUNT,FREMAINQTY,FREMAINAMOUNT)").append("\r\n");
/* 777*/        sqlAll.append("Select 0 as FIndex,FCompanyOrgUnitID,FCompanyName,FYear,FPeriod,FMaterialID,FMaterialName,FMaterialNumber,").append("\r\n");
/* 778*/        sqlAll.append("FSHORTNAME,FMaterialModel,FBaseUnitName,FSumTypeID,FSumTypeName,sum(FBeginQty),sum(FBeginAmount),").append("\r\n");
/* 779*/        sqlAll.append("sum(FInQty),sum(FINAmount),sum(FOutQty),sum(FOutAmount),sum(FRemainQty),sum(FRemainAmount)").append("\r\n");
/* 780*/        sqlAll.append("From ( ").append("\r\n");
/* 782*/        sqlAll.append(getStockSQL(ctx, tempTable, params)).append("\r\n");
/* 784*/        boolean hasCurrAndAfterPeriod = params.getBoolean("hasCurrAndAfterPeriod");
/* 785*/        if(hasCurrAndAfterPeriod)
                {
/* 786*/            sqlAll.append("\r\n UNION All  \r\n");
/* 787*/            sqlAll.append(getCurrPeriodBillSQL(ctx, tempTable, params));
                }
/* 789*/        sqlAll.append(") T Group by FCompanyOrgUnitID,FCompanyName,FYear,FPeriod,FMaterialID,FMaterialName,").append("\r\n");
/* 790*/        sqlAll.append("FMaterialNumber,FSHORTNAME,FMaterialModel,FBaseUnitName,FSumTypeID,FSumTypeName").append("\r\n");
/* 792*/        return sqlAll.toString();
            }

            private String getCurrPeriodBillSQL(Context ctx, String tempTable, RptParams params)
                throws BOSException
            {
/* 805*/        String fiOrgUnitID = null;
/* 806*/        String MaterialFrom = null;
/* 807*/        String MaterialTo = null;
/* 808*/        String warehouse = null;
/* 809*/        String txtMShortNameFrom = null;
/* 810*/        String txtMShortNameTo = null;
/* 811*/        String SumTypeFieldName = null;
/* 812*/        boolean noSelectMoveBill = false;
/* 813*/        boolean ckShowNoCalculate = false;
/* 814*/        int voucher = -1;
/* 817*/        if(params.getObject("company") != null)
/* 818*/            fiOrgUnitID = ((CompanyOrgUnitInfo)params.getObject("company")).getId().toString();
/* 821*/        if(params.getObject("materialFrom") != null)
/* 822*/            if(params.getObject("materialFrom") instanceof MaterialInfo)
/* 823*/                MaterialFrom = ((MaterialInfo)params.getObject("materialFrom")).getNumber();
/* 825*/            else
/* 825*/                MaterialFrom = params.getObject("materialFrom").toString();
/* 827*/        if(params.getObject("materialTo") != null)
/* 828*/            if(params.getObject("materialTo") instanceof MaterialInfo)
/* 829*/                MaterialTo = ((MaterialInfo)params.getObject("materialTo")).getNumber();
/* 832*/            else
/* 832*/                MaterialTo = params.getObject("materialTo").toString();
/* 834*/        if(params.getObject("sumType") != null)
/* 835*/            SumTypeFieldName = ((SumTypeEnum)params.getObject("sumType")).getValue().toString();
/* 839*/        KAClassficationInfo prmtKAClass = (KAClassficationInfo)params.getObject("prmtKAClass");
/* 840*/        String kaClassID = null;
/* 841*/        if(prmtKAClass != null)
/* 842*/            kaClassID = prmtKAClass.getId().toString();
/* 845*/        if(params.getString("warehouse") != null)
/* 846*/            warehouse = params.getString("warehouse");
/* 849*/        txtMShortNameFrom = params.getString("txtMShortNameFrom");
/* 850*/        txtMShortNameTo = params.getString("txtMShortNameTo");
/* 852*/        ckShowNoCalculate = params.getBoolean("ckShowNoCalculate");
/* 854*/        noSelectMoveBill = params.getBoolean("noSelectMoveBill");
/* 856*/        voucher = ((VoucheredEnum)params.getObject("voucher")).getValue();
/* 858*/        StringBuffer sqlSelect = new StringBuffer();
/* 859*/        sqlSelect.append("SELECT 0 as FIndex, ");
/* 860*/        sqlSelect.append("d.FCompanyOrgUnitID as FCompanyOrgUnitID, ");
/* 861*/        sqlSelect.append("fi.FName_" + getLoc(ctx) + " as FCompanyName, ");
/* 862*/        sqlSelect.append("h.FYear as FYear, ");
/* 863*/        sqlSelect.append("h.FPeriod as FPeriod, ");
/* 864*/        sqlSelect.append("d.FMaterialID as FMaterialID, ");
/* 865*/        sqlSelect.append("m.FName_" + getLoc(ctx) + " as FMaterialName, ");
/* 866*/        sqlSelect.append("m.FNumber as FMaterialNumber, ");
/* 867*/        sqlSelect.append("m.FSHORTNAME as FSHORTNAME, ");
/* 868*/        sqlSelect.append("m.FModel as FMaterialModel, ");
/* 869*/        sqlSelect.append("mu.FName_" + getLoc(ctx) + " as FBaseUnitName, ");
/* 871*/        if(SumTypeFieldName.equals("FCalculateType"))
                {
/* 872*/            sqlSelect.append("mcom.FCalculateType as FSumTypeID,");
/* 873*/            sqlSelect.append("(case when mcom.FCalculateType=0 then '" + SCMUtils.getResource(res, "PURCHASE", ctx) + "' else (case when mcom.FCalculateType=1 then '" + SCMUtils.getResource(res, "CONSIGN", ctx) + "' else (case when mcom.FCalculateType=2 then '" + SCMUtils.getResource(res, "MAKE", ctx) + "' else ' ' end) end) end) as FSumTypeName, ");
                } else
/* 880*/        if(SumTypeFieldName.equals("FStorageOrgUnit"))
                {
/* 881*/            sqlSelect.append("d.FStorageOrgUnitID as FSumTypeID, ");
/* 882*/            sqlSelect.append("so.FName_" + getLoc(ctx) + " as FSumTypeName, ");
                } else
/* 883*/        if(SumTypeFieldName.equals("FWarehouse"))
                {
/* 884*/            sqlSelect.append("d.FWarehouseID as FSumTypeID, ");
/* 885*/            sqlSelect.append("wh.FName_" + getLoc(ctx) + " as FSumTypeName, ");
                } else
/* 886*/        if(SumTypeFieldName.equals("FKAClassfication"))
                {
/* 887*/            sqlSelect.append("mcom.FKAClassID as FSumTypeID,");
/* 888*/            sqlSelect.append("ka.FName_" + getLoc(ctx) + " as FSumTypeName, ");
                } else
/* 889*/        if(SumTypeFieldName.equals("FMaterialGroupLevel"))
                {
/* 890*/            sqlSelect.append("'1' as FSumTypeID,");
/* 891*/            sqlSelect.append("'2' as FSumTypeName, ");
                }
/* 893*/        sqlSelect.append("0 as FBeginQty, ");
/* 894*/        sqlSelect.append("0 as FBeginAmount, ");
/* 896*/        String sqlIn = "sum(d.FBaseQty) as FInQty,";
/* 897*/        sqlIn = sqlIn + "CASE mcom.FAccountType WHEN 2 THEN sum(d.FStandardCost) ELSE sum(d.FActualCost) END as FInAmount,";
/* 898*/        sqlIn = sqlIn + "0 as FOutQty,0 as FOutAmount, ";
/* 899*/        sqlIn = sqlIn + "0 as FRemainQty,0 as FRemainAmount ";
/* 901*/        String sqlOut = "0 as FInQty,0 as FInAmount,";
/* 902*/        sqlOut = sqlOut + "sum(d.FBaseQty) as FOutQty,";
/* 903*/        sqlOut = sqlOut + "CASE mcom.FAccountType WHEN 2 THEN sum(d.FStandardCost) ELSE sum(d.FActualCost) END as FOutAmount,";
/* 904*/        sqlOut = sqlOut + "0 as FRemainQty,0 as FRemainAmount ";
/* 907*/        String sqlInOut = "0 as FInQty,";
/* 908*/        sqlInOut = sqlInOut + "case h.FCalculateKind when 0 then (CASE mcom.FAccountType WHEN 2 THEN 0 ELSE sum(d.FActualCost) END) end as FInAmount,";
/* 909*/        sqlInOut = sqlInOut + "0 as FOutQty,";
/* 910*/        sqlInOut = sqlInOut + "case h.FCalculateKind when 1 then (CASE mcom.FAccountType WHEN 2 THEN 0 ELSE sum(d.FActualCost) END) end as FOutAmount,";
/* 911*/        sqlInOut = sqlInOut + "0 as FRemainQty,0 as FRemainAmount ";
/* 913*/        StringBuffer sqlWhere = new StringBuffer();
/* 915*/        sqlWhere.append(" WHERE (h.FIsInitBill = 0 or h.FIsInitBill is null ) ");
/* 918*/        if(voucher != -1)
/* 919*/            sqlWhere.append("And h.ffiVouchered = ").append(voucher).append(" ");
/* 922*/        if(kaClassID != null)
/* 923*/            sqlWhere.append("And mcom.FKAClassID = '").append(kaClassID).append("' ");
/* 926*/        sqlWhere.append(" And d.FCompanyOrgUnitID = '" + fiOrgUnitID + "' ");
/* 928*/        int status = -1;
/* 929*/        if(params.getObject("status") != null)
                {
/* 930*/            status = ((BillBaseStatusEnum)params.getObject("status")).getValue();
/* 931*/            if(status == 2)
/* 932*/                sqlWhere.append(" AND h.FBaseStatus = " + String.valueOf(status) + " ");
/* 933*/            else
/* 933*/            if(status == 4)
/* 934*/                sqlWhere.append(" AND h.FBaseStatus = " + String.valueOf(status) + " ");
/* 937*/            else
/* 937*/                sqlWhere.append(" And (h.FBaseStatus = ").append(2).append(" or").append(" h.FBaseStatus = ").append(4).append(")");
                }
/* 943*/        String psql = params.getString("whereCurrAndAfterPeriodSql");
/* 945*/        sqlWhere.append(" AND (").append(psql).append(") ");
/* 947*/        if(MaterialFrom != null)
/* 948*/            sqlWhere.append(" AND m.FNumber >= '" + MaterialFrom + "' ");
/* 949*/        if(MaterialTo != null)
/* 950*/            sqlWhere.append(" AND m.FNumber <= '" + MaterialTo + "' ");
/* 953*/        if(warehouse != null)
/* 954*/            sqlWhere.append(" AND wh.FNumber in(" + warehouse + ")");
/* 957*/        if(params.getObject("ckBxMShortName") != null && params.getBoolean("ckBxMShortName"))
/* 958*/            if(params.getBoolean("ckBxMShortName") && txtMShortNameFrom.trim().length() > 0 && txtMShortNameTo.trim().length() > 0)
/* 959*/                sqlWhere.append(" AND M.FShortName >= '" + txtMShortNameFrom + "' AND M.FShortName <= '" + txtMShortNameTo + "' ");
/* 960*/            else
/* 960*/            if(params.getBoolean("ckBxMShortName") && txtMShortNameFrom.trim().length() > 0 && txtMShortNameTo.trim().length() <= 0)
/* 961*/                sqlWhere.append(" AND M.FShortName >= '" + txtMShortNameFrom + "' ");
/* 962*/            else
/* 962*/            if(params.getBoolean("ckBxMShortName") && txtMShortNameFrom.trim().length() <= 0 && txtMShortNameTo.trim().length() > 0)
/* 963*/                sqlWhere.append(" AND M.FShortName <= '" + txtMShortNameTo + "' ");
/* 967*/        String sqlWhereCostAdj = sqlWhere.toString();
/* 968*/        if(!ckShowNoCalculate)
/* 969*/            sqlWhere.append(" And tr.FIsCalculate = 1 ");
/* 972*/        StringBuffer sqlGroup = new StringBuffer();
/* 973*/        sqlGroup.append("GRoup by d.FCompanyOrgUnitID,fi.FName_" + getLoc(ctx) + ",");
/* 974*/        sqlGroup.append("h.FYear,h.FPeriod,");
/* 975*/        sqlGroup.append("d.FMaterialID,m.FName_" + getLoc(ctx) + ",");
/* 976*/        sqlGroup.append("m.FNumber,m.FSHORTNAME,m.FModel,");
/* 977*/        sqlGroup.append("mu.FName_" + getLoc(ctx) + ",");
/* 978*/        sqlGroup.append("mcom.FAccountType");
/* 980*/        if(SumTypeFieldName.equals("FCalculateType"))
/* 981*/            sqlGroup.append(",mcom.FCalculateType ");
/* 982*/        else
/* 982*/        if(SumTypeFieldName.equals("FStorageOrgUnit"))
                {
/* 983*/            sqlGroup.append(",d.FStorageOrgUnitID,");
/* 984*/            sqlGroup.append("so.FName_" + getLoc(ctx) + " ");
                } else
/* 985*/        if(SumTypeFieldName.equals("FWarehouse"))
                {
/* 986*/            sqlGroup.append(",d.FWarehouseID,");
/* 987*/            sqlGroup.append("wh.FName_" + getLoc(ctx) + " ");
                } else
/* 988*/        if(SumTypeFieldName.equals("FKAClassfication"))
                {
/* 989*/            sqlGroup.append(",mcom.FKAClassID,");
/* 990*/            sqlGroup.append("ka.FName_" + getLoc(ctx) + " ");
                }
/* 992*/        String sql = "";
/* 993*/        StringBuffer sqlAll = new StringBuffer();
/* 995*/        sql = sqlSelect.toString() + sqlIn;
/* 996*/        sql = sql + sqlFrom(ctx, "T_IM_PurInWarehsBill", "T_IM_PurInWarehsEntry", SumTypeFieldName);
/* 998*/        sql = sql + sqlWhere.toString() + sqlGroup.toString();
/* 999*/        sqlAll.append(sql + "\r\n UNION All  \r\n");
/*1002*/        sql = sqlSelect.toString() + sqlIn;
/*1003*/        sql = sql + sqlFrom(ctx, "T_IM_ManufactureRecBill", "T_IM_ManufactureRecBillEntry", SumTypeFieldName);
/*1005*/        sql = sql + sqlWhere.toString() + sqlGroup.toString();
/*1006*/        sqlAll.append(sql + "\r\n UNION All  \r\n");
/*1009*/        sql = sqlSelect.toString() + sqlIn;
/*1011*/        if(noSelectMoveBill)
                {
/*1013*/            sql = sql + sqlForMoveInOut(ctx, "T_IM_MoveInWarehsBill", "T_IM_MoveInWarehsBillEntry", SumTypeFieldName);
/*1015*/            sql = sql + sqlWhere.toString();
/*1016*/            sql = sql + "and bz.fid <>'d8e80652-011a-1000-e000-04c5c0a812202407435C' and bz.fid <>'d8e80652-011b-1000-e000-04c5c0a812202407435C' ";
/*1018*/            sql = sql + sqlGroup.toString();
                } else
                {
/*1020*/            sql = sql + sqlFrom(ctx, "T_IM_MoveInWarehsBill", "T_IM_MoveInWarehsBillEntry", SumTypeFieldName);
/*1022*/            sql = sql + sqlWhere.toString() + sqlGroup.toString();
                }
/*1025*/        sqlAll.append(sql + "\r\n UNION All  \r\n");
/*1028*/        sql = sqlSelect.toString() + sqlIn;
/*1029*/        sql = sql + sqlFrom(ctx, "T_IM_OtherInWarehsBill", "T_IM_OtherInWarehsBillEntry", SumTypeFieldName);
/*1031*/        sql = sql + sqlWhere.toString() + sqlGroup.toString();
/*1032*/        sqlAll.append(sql + "\r\n UNION All  \r\n");
/*1035*/        sql = sqlSelect.toString() + sqlOut;
/*1036*/        sql = sql + sqlFrom(ctx, "T_IM_SaleIssueBill", "T_IM_SaleIssueEntry", SumTypeFieldName);
/*1038*/        sql = sql + sqlWhere.toString() + sqlGroup.toString();
/*1039*/        sqlAll.append(sql + "\r\n UNION All  \r\n");
/*1042*/        sql = sqlSelect.toString() + sqlOut;
/*1043*/        sql = sql + sqlFrom(ctx, "T_IM_MaterialReqBill", "T_IM_MaterialReqBillEntry", SumTypeFieldName);
/*1045*/        sql = sql + sqlWhere.toString() + sqlGroup.toString();
/*1046*/        sqlAll.append(sql + "\r\n UNION All  \r\n");
/*1049*/        sql = sqlSelect.toString() + sqlOut;
/*1050*/        if(noSelectMoveBill)
                {
/*1052*/            sql = sql + sqlForMoveInOut(ctx, "T_IM_MoveIssueBill", "T_IM_MoveIssueBillEntry", SumTypeFieldName);
/*1054*/            sql = sql + sqlWhere.toString();
/*1055*/            sql = sql + "and bz.fid <>'d8e80652-011a-1000-e000-04c5c0a812202407435C' and bz.fid <>'d8e80652-011b-1000-e000-04c5c0a812202407435C' ";
/*1057*/            sql = sql + sqlGroup.toString();
                } else
                {
/*1059*/            sql = sql + sqlFrom(ctx, "T_IM_MoveIssueBill", "T_IM_MoveIssueBillEntry", SumTypeFieldName);
/*1061*/            sql = sql + sqlWhere.toString() + sqlGroup.toString();
                }
/*1064*/        sqlAll.append(sql + "\r\n UNION All  \r\n");
/*1067*/        sql = sqlSelect.toString() + sqlOut;
/*1068*/        sql = sql + sqlFrom(ctx, "T_IM_OtherIssueBill", "T_IM_OtherIssueBillEntry", SumTypeFieldName);
/*1070*/        sql = sql + sqlWhere.toString() + sqlGroup.toString();
/*1071*/        sqlAll.append(sql + "\r\n UNION All  \r\n");
/*1074*/        sqlGroup.append(",h.FCalculateKind");
/*1075*/        sql = sqlSelect.toString() + sqlInOut;
/*1076*/        sql = sql + sqlFrom(ctx, "T_CL_CostAdjustBill", "T_CL_CostAdjustBillEntry", SumTypeFieldName);
/*1079*/        sql = sql + sqlWhereCostAdj + sqlGroup.toString();
/*1080*/        sqlAll.append(sql + "\r\n UNION All  \r\n");
/*1083*/        sql = GetStdAdjBillSQL(ctx, tempTable, params);
/*1084*/        sqlAll.append(sql);
/*1085*/        return sqlAll.toString();
            }

            private String GetStdAdjBillSQL(Context ctx, String tempTable, RptParams params)
                throws BOSException
            {
/*1097*/        String fiOrgUnitID = null;
/*1098*/        fiOrgUnitID = ((CompanyOrgUnitInfo)params.getObject("company")).getId().toString();
/*1101*/        String SumTypeFieldName = null;
/*1102*/        SumTypeFieldName = ((SumTypeEnum)params.getObject("sumType")).getValue().toString();
/*1105*/        String MaterialFrom = null;
/*1106*/        if(params.getObject("materialFrom") != null)
/*1107*/            if(params.getObject("materialFrom") instanceof MaterialInfo)
/*1108*/                MaterialFrom = ((MaterialInfo)params.getObject("materialFrom")).getNumber();
/*1110*/            else
/*1110*/                MaterialFrom = params.getObject("materialFrom").toString();
/*1112*/        String MaterialTo = null;
/*1113*/        if(params.getObject("materialTo") != null)
/*1114*/            if(params.getObject("materialTo") instanceof MaterialInfo)
/*1115*/                MaterialTo = ((MaterialInfo)params.getObject("materialTo")).getNumber();
/*1118*/            else
/*1118*/                MaterialTo = params.getObject("materialTo").toString();
/*1120*/        String warehouse = null;
/*1123*/        if(params.getString("warehouse") != null)
/*1124*/            warehouse = params.getString("warehouse");
/*1129*/        String txtMShortNameFrom = params.getString("txtMShortNameFrom");
/*1130*/        String txtMShortNameTo = params.getString("txtMShortNameTo");
/*1132*/        StringBuffer sql = new StringBuffer();
/*1134*/        sql.append("SELECT 0 as FIndex, ");
/*1135*/        sql.append("i.FCompanyOrgUnitID as FCompanyOrgUnitID, ");
/*1136*/        sql.append("fi.FName_" + getLoc(ctx) + " as FCompanyName, ");
/*1137*/        sql.append("i.FYear as FYear, ");
/*1138*/        sql.append("i.FPeriod as FPeriod, ");
/*1139*/        sql.append("i.FMaterialID as FMaterialID, ");
/*1140*/        sql.append("m.FName_" + getLoc(ctx) + " as FMaterialName, ");
/*1141*/        sql.append("m.FNumber as FMaterialNumber, ");
/*1142*/        sql.append("m.FSHORTNAME as FSHORTNAME, ");
/*1143*/        sql.append("m.FModel as FMaterialModel, ");
/*1144*/        sql.append("mu.FName_" + getLoc(ctx) + " as FBaseUnitName, ");
/*1146*/        if(SumTypeFieldName.equals("FCalculateType"))
                {
/*1147*/            sql.append("mcom.FCalculateType as FSumTypeID,");
/*1148*/            sql.append("(case when mcom.FCalculateType=0 then '" + SCMUtils.getResource(res, "PURCHASE", ctx) + "' else (case when mcom.FCalculateType=1 then '" + SCMUtils.getResource(res, "CONSIGN", ctx) + "' else (case when mcom.FCalculateType=2 then '" + SCMUtils.getResource(res, "MAKE", ctx) + "' else ' ' end) end) end) as FSumTypeName, ");
                } else
/*1155*/        if(SumTypeFieldName.equals("FStorageOrgUnit"))
                {
/*1156*/            sql.append("i.FStorageOrgUnitID as FSumTypeID, ");
/*1157*/            sql.append("so.FName_" + getLoc(ctx) + " as FSumTypeName, ");
                } else
/*1158*/        if(SumTypeFieldName.equals("FWarehouse"))
                {
/*1159*/            sql.append("i.FWarehouseID as FSumTypeID, ");
/*1160*/            sql.append("wh.FName_" + getLoc(ctx) + " as FSumTypeName, ");
                } else
/*1161*/        if(SumTypeFieldName.equals("FKAClassfication"))
                {
/*1162*/            sql.append("mcom.FKAClassID as FSumTypeID,");
/*1163*/            sql.append("ka.FName_" + getLoc(ctx) + " as FSumTypeName,");
                } else
/*1164*/        if(SumTypeFieldName.equals("FMaterialGroupLevel"))
                {
/*1165*/            sql.append("'1' as FSumTypeID,");
/*1166*/            sql.append("'2' as FSumTypeName, ");
                }
/*1168*/        sql.append("0 as FBeginQty, ");
/*1169*/        sql.append("0 as FBeginAmount, ");
/*1170*/        sql.append("0 as FInQty, ");
/*1171*/        sql.append("sum(i.FPeriodAdjustDiff) as FInAmount,");
/*1172*/        sql.append("0 as FOutQty, ");
/*1173*/        sql.append("0 as FOutAmount, ");
/*1174*/        sql.append("0 as FRemainQty, ");
/*1175*/        sql.append("0 as FRemainAmount \r\n");
/*1176*/        sql.append("From T_IM_InventoryBalance i \r\n");
/*1177*/        sql.append("INNER Join T_BD_Material m On i.FMaterialID=m.FID \r\n");
/*1178*/        sql.append("INNER JOIN t_org_company fi ON i.FCompanyOrgUnitID = fi.FID \r\n");
/*1179*/        sql.append("INNER JOIN T_BD_MaterialCompanyInfo mcom On i.FMaterialID = mcom.FMaterialID  AND mcom.FCompanyID = i.FCompanyOrgUnitID \r\n");
/*1180*/        sql.append("Inner Join T_DB_WAREHOUSE wh on i.FWarehouseID = wh.FID \r\n");
/*1181*/        sql.append("Inner Join T_ORG_Storage so on i.FStorageOrgUnitID = so.FID \r\n");
/*1182*/        sql.append("INNER JOIN T_BD_MeasureUnit mu ON m.FBaseUnit = mu.FID \r\n");
/*1183*/        sql.append("LEFT JOIN T_BD_KAClassfication ka ON mcom.FKAClassID = ka.FID \r\n");
/*1185*/        sql.append("WHERE i.FPeriodAdjustDiff<>0 And i.FCompanyOrgUnitID = '" + fiOrgUnitID + "' ");
/*1187*/        String psql = params.getString("whereCurrAndAfterPeriodSql");
/*1188*/        psql = psql.replaceAll("h.", "i.");
/*1189*/        sql.append(" AND (").append(psql).append(") ");
/*1191*/        if(MaterialFrom != null)
/*1192*/            sql.append(" AND m.FNumber >= '" + MaterialFrom + "' ");
/*1193*/        if(MaterialTo != null)
/*1194*/            sql.append(" AND m.FNumber <= '" + MaterialTo + "' ");
/*1197*/        if(params.getObject("ckBxMShortName") != null && params.getBoolean("ckBxMShortName"))
/*1198*/            if(params.getBoolean("ckBxMShortName") && txtMShortNameFrom.trim().length() > 0 && txtMShortNameTo.trim().length() > 0)
/*1199*/                sql.append(" AND M.FShortName >= '" + txtMShortNameFrom + "' AND M.FShortName <= '" + txtMShortNameTo + "' ");
/*1200*/            else
/*1200*/            if(params.getBoolean("ckBxMShortName") && txtMShortNameFrom.trim().length() > 0 && txtMShortNameTo.trim().length() <= 0)
/*1201*/                sql.append(" AND M.FShortName >= '" + txtMShortNameFrom + "' ");
/*1202*/            else
/*1202*/            if(params.getBoolean("ckBxMShortName") && txtMShortNameFrom.trim().length() <= 0 && txtMShortNameTo.trim().length() > 0)
/*1203*/                sql.append(" AND M.FShortName <= '" + txtMShortNameTo + "' ");
/*1207*/        if(warehouse != null)
/*1208*/            sql.append(" AND wh.FNumber in(" + warehouse + ")");
/*1211*/        KAClassficationInfo prmtKAClass = (KAClassficationInfo)params.getObject("prmtKAClass");
/*1212*/        if(prmtKAClass != null)
/*1213*/            sql.append(" AND mcom.FKAClassID = '").append(prmtKAClass.getId().toString()).append("' ");
/*1216*/        sql.append("\r\n GRoup by i.FCompanyOrgUnitID,fi.FName_" + getLoc(ctx) + ",");
/*1217*/        sql.append("i.FYear,i.FPeriod,");
/*1218*/        sql.append("i.FMaterialID,m.FName_" + getLoc(ctx) + ",");
/*1219*/        sql.append("m.FNumber,m.FSHORTNAME,m.FModel,");
/*1220*/        sql.append("mu.FName_" + getLoc(ctx) + ",");
/*1221*/        sql.append("mcom.FAccountType");
/*1223*/        if(SumTypeFieldName.equals("FCalculateType"))
/*1224*/            sql.append(",mcom.FCalculateType ");
/*1225*/        else
/*1225*/        if(SumTypeFieldName.equals("FStorageOrgUnit"))
                {
/*1226*/            sql.append(",i.FStorageOrgUnitID,");
/*1227*/            sql.append("so.FName_" + getLoc(ctx) + " ");
                } else
/*1228*/        if(SumTypeFieldName.equals("FWarehouse"))
                {
/*1229*/            sql.append(",i.FWarehouseID,");
/*1230*/            sql.append("wh.FName_" + getLoc(ctx) + " ");
                } else
/*1231*/        if(SumTypeFieldName.equals("FKAClassfication"))
                {
/*1232*/            sql.append(",mcom.FKAClassID,");
/*1233*/            sql.append("ka.FName_" + getLoc(ctx) + " ");
                }
/*1236*/        return sql.toString();
            }

            private String getStockSQL(Context ctx, String tempTable, RptParams params)
                throws EASBizException, BOSException
            {
/*1249*/        String fiOrgUnitID = null;
/*1250*/        fiOrgUnitID = ((CompanyOrgUnitInfo)params.getObject("company")).getId().toString();
/*1253*/        String SumTypeFieldName = null;
/*1254*/        SumTypeFieldName = ((SumTypeEnum)params.getObject("sumType")).getValue().toString();
/*1257*/        String MaterialFrom = null;
/*1258*/        if(params.getObject("materialFrom") != null)
/*1259*/            if(params.getObject("materialFrom") instanceof MaterialInfo)
/*1260*/                MaterialFrom = ((MaterialInfo)params.getObject("materialFrom")).getNumber();
/*1262*/            else
/*1262*/                MaterialFrom = params.getObject("materialFrom").toString();
/*1264*/        String MaterialTo = null;
/*1265*/        if(params.getObject("materialTo") != null)
/*1266*/            if(params.getObject("materialTo") instanceof MaterialInfo)
/*1267*/                MaterialTo = ((MaterialInfo)params.getObject("materialTo")).getNumber();
/*1270*/            else
/*1270*/                MaterialTo = params.getObject("materialTo").toString();
/*1271*/        String warehouse = null;
/*1274*/        if(params.getString("warehouse") != null)
/*1275*/            warehouse = params.getString("warehouse");
/*1277*/        StringBuffer sql = new StringBuffer();
/*1279*/        sql.append("SELECT 0 as FIndex, ");
/*1280*/        sql.append("d.FCompanyOrgUnitID as FCompanyOrgUnitID, ");
/*1281*/        sql.append("fi.FName_" + getLoc(ctx) + " as FCompanyName, ");
/*1282*/        sql.append("d.FYear as FYear, ");
/*1283*/        sql.append("d.FPeriod as FPeriod, ");
/*1284*/        sql.append("d.FMaterialID as FMaterialID, ");
/*1285*/        sql.append("m.FName_" + getLoc(ctx) + " as FMaterialName, ");
/*1286*/        sql.append("m.FNumber as FMaterialNumber, ");
/*1287*/        sql.append("m.FSHORTNAME as FSHORTNAME, ");
/*1288*/        sql.append("m.FModel as FMaterialModel, ");
/*1289*/        sql.append("mu.FName_" + getLoc(ctx) + " as FBaseUnitName, ");
/*1290*/        if(SumTypeFieldName.equals("FCalculateType"))
                {
/*1291*/            sql.append("mcom.FCalculateType as FSumTypeID,");
/*1292*/            sql.append("(case when mcom.FCalculateType=0 then '" + SCMUtils.getResource(res, "PURCHASE", ctx) + "' else (case when mcom.FCalculateType=1 then '" + SCMUtils.getResource(res, "CONSIGN", ctx) + "' else (case when mcom.FCalculateType=2 then '" + SCMUtils.getResource(res, "MAKE", ctx) + "' else ' ' end) end) end) as FSumTypeName, ");
                } else
/*1299*/        if(SumTypeFieldName.equals("FStorageOrgUnit"))
                {
/*1300*/            sql.append("d.FStorageOrgUnitID as FSumTypeID, ");
/*1301*/            sql.append("so.FName_" + getLoc(ctx) + " as FSumTypeName, ");
                } else
/*1302*/        if(SumTypeFieldName.equals("FWarehouse"))
                {
/*1303*/            sql.append("d.FWarehouseID as FSumTypeID, ");
/*1304*/            sql.append("wh.FName_" + getLoc(ctx) + " as FSumTypeName, ");
                } else
/*1305*/        if(SumTypeFieldName.equals("FKAClassfication"))
                {
/*1306*/            sql.append("mcom.FKAClassID as FSumTypeID, ");
/*1307*/            sql.append("ka.FName_" + getLoc(ctx) + " as FSumTypeName, ");
                } else
/*1308*/        if(SumTypeFieldName.equals("FMaterialGroupLevel"))
                {
/*1309*/            sql.append("'1' as FSumTypeID,");
/*1310*/            sql.append("'2' as FSumTypeName, ");
                }
/*1313*/        sql.append("sum(d.FPeriodBeginQty) as FBeginQty, ");
/*1314*/        sql.append("sum(d.FPERIODBEGINBALANCE) as FBeginAmount, ");
/*1315*/        sql.append("sum(d.FPeriodReceiptQty) as FInQty,sum(d.FPeriodReceiptAmount) as FInAmount,");
/*1316*/        sql.append("sum(d.FPeriodIssueQty) as FOutQty,sum(d.FPeriodIssueAmount) as FOutAmount,");
/*1317*/        sql.append("sum(d.FPeriodEndQty) as FRemainQty,");
/*1318*/        sql.append("sum(d.FPeriodEndBalance) as FRemainAmount \r\n");
/*1320*/        sql.append("From T_IM_InventoryBalance d \r\n");
/*1321*/        sql.append("Inner Join T_BD_Material m On d.FMaterialID=m.FID \r\n");
/*1322*/        sql.append("INNER JOIN t_org_company fi ON d.FCompanyOrgUnitID = fi.FID \r\n");
/*1323*/        sql.append("INNER JOIN T_BD_MeasureUnit mu ON m.FBaseUnit = mu.FID \r\n");
/*1324*/        sql.append("INNER JOIN T_BD_MaterialCompanyInfo mcom On d.FMaterialID = mcom.FMaterialID  AND mcom.FCompanyID = d.FCompanyOrgUnitID \r\n");
/*1326*/        sql.append("Inner Join T_DB_WAREHOUSE wh on d.FWarehouseID = wh.FID \r\n");
/*1327*/        sql.append("Inner Join T_ORG_Storage so on d.FStorageOrgUnitID = so.FID \r\n");
/*1328*/        sql.append("LEFT JOIN T_BD_KAClassfication ka ON mcom.FKAClassID = ka.FID \r\n");
/*1331*/        sql.append("Where d.FCompanyOrgUnitID = '" + fiOrgUnitID + "' ");
/*1333*/        String psql = params.getString("wherePeriodSql");
/*1334*/        psql = psql.replaceAll("h.", "d.");
/*1336*/        sql.append(" AND (").append(psql).append(") ");
/*1338*/        if(MaterialFrom != null)
/*1339*/            sql.append(" AND m.FNumber >= '" + MaterialFrom + "' ");
/*1340*/        if(MaterialTo != null)
/*1341*/            sql.append(" AND m.FNumber <= '" + MaterialTo + "' ");
/*1344*/        if(warehouse != null)
/*1345*/            sql.append(" AND wh.FNumber in(" + warehouse + ")");
/*1350*/        String txtMShortNameFrom = params.getString("txtMShortNameFrom");
/*1351*/        String txtMShortNameTo = params.getString("txtMShortNameTo");
/*1353*/        if(params.getObject("ckBxMShortName") != null && params.getBoolean("ckBxMShortName"))
/*1354*/            if(params.getBoolean("ckBxMShortName") && txtMShortNameFrom.trim().length() > 0 && txtMShortNameTo.trim().length() > 0)
/*1355*/                sql.append(" AND M.FShortName >= '" + txtMShortNameFrom + "' AND M.FShortName <= '" + txtMShortNameTo + "' ");
/*1356*/            else
/*1356*/            if(params.getBoolean("ckBxMShortName") && txtMShortNameFrom.trim().length() > 0 && txtMShortNameTo.trim().length() <= 0)
/*1357*/                sql.append(" AND M.FShortName >= '" + txtMShortNameFrom + "' ");
/*1358*/            else
/*1358*/            if(params.getBoolean("ckBxMShortName") && txtMShortNameFrom.trim().length() <= 0 && txtMShortNameTo.trim().length() > 0)
/*1359*/                sql.append(" AND M.FShortName <= '" + txtMShortNameTo + "' ");
/*1364*/        KAClassficationInfo prmtKAClass = (KAClassficationInfo)params.getObject("prmtKAClass");
/*1365*/        if(prmtKAClass != null)
/*1366*/            sql.append(" AND mcom.FKAClassID = '").append(prmtKAClass.getId().toString()).append("' ");
/*1370*/        boolean ckShowNoCalculate = params.getBoolean("ckShowNoCalculate");
/*1372*/        boolean noSelectMoveBill = params.getBoolean("noSelectMoveBill");
/*1375*/        if(!ckShowNoCalculate && !noSelectMoveBill)
/*1376*/            sql.append(" AND (d.FIsCalculate = 1 or d.FMoveType in (1,2))");
/*1377*/        else
/*1377*/        if(!ckShowNoCalculate && noSelectMoveBill)
/*1378*/            sql.append(" AND (d.FIsCalculate = 1 and d.FMoveType = 0)");
/*1379*/        else
/*1379*/        if(ckShowNoCalculate && noSelectMoveBill)
/*1380*/            sql.append(" AND d.FMoveType = 0 ");
/*1384*/        sql.append(" AND d.FStoreTypeId IN (").append("\r\n");
/*1385*/        sql.append(" '").append("181875d5-0105-1000-e000-0111c0a812fd97D461A6").append("',").append("\r\n");
/*1386*/        sql.append(" '").append("181875d5-0105-1000-e000-011ac0a812fd97D461A6").append("',").append("\r\n");
/*1387*/        sql.append(" '").append("181875d5-0105-1000-e000-0123c0a812fd97D461A6").append("')").append("\r\n");
/*1389*/        sql.append("\r\n");
/*1391*/        sql.append("Group by d.FCompanyOrgUnitID,fi.FName_" + getLoc(ctx) + ",");
/*1392*/        sql.append("d.FYear,d.FPeriod,");
/*1393*/        sql.append("d.FMaterialID,m.FName_" + getLoc(ctx) + ",");
/*1394*/        sql.append("m.FNumber,m.FSHORTNAME,m.FModel,");
/*1395*/        sql.append("mu.FName_" + getLoc(ctx) + "");
/*1397*/        if(SumTypeFieldName.equals("FCalculateType"))
/*1398*/            sql.append(",mcom.FCalculateType ");
/*1399*/        else
/*1399*/        if(SumTypeFieldName.equals("FStorageOrgUnit"))
                {
/*1400*/            sql.append(",d.FStorageOrgUnitID,");
/*1401*/            sql.append("so.FName_" + getLoc(ctx));
                } else
/*1402*/        if(SumTypeFieldName.equals("FWarehouse"))
                {
/*1403*/            sql.append(",d.FWarehouseID,");
/*1404*/            sql.append("wh.FName_" + getLoc(ctx));
                } else
/*1405*/        if(SumTypeFieldName.equals("FKAClassfication"))
                {
/*1406*/            sql.append(",mcom.FKAClassID,");
/*1407*/            sql.append("ka.FName_" + getLoc(ctx));
                }
/*1410*/        return sql.toString();
            }

            private String sqlFrom(Context ctx, String headTbale, String entryTable, String SumTypeFieldName)
            {
/*1415*/        StringBuffer sql = new StringBuffer();
/*1416*/        sql.append(" From " + headTbale + " h \r\n");
/*1417*/        sql.append("INNER JOIN " + entryTable + " d ON h.FID = d.FParentID \r\n");
/*1418*/        sql.append("Inner Join T_BD_Material m On d.FMaterialID=m.FID \r\n");
/*1419*/        sql.append("INNER JOIN t_org_company fi ON d.FCompanyOrgUnitID = fi.FID \r\n");
/*1420*/        sql.append("INNER JOIN T_BD_MaterialCompanyInfo mcom On d.FMaterialID = mcom.FMaterialID  AND mcom.FCompanyID = d.FCompanyOrgUnitID \r\n");
/*1421*/        sql.append("Inner Join T_DB_WAREHOUSE wh on d.FWarehouseID = wh.FID \r\n");
/*1422*/        sql.append("Inner Join T_ORG_Storage so on h.FStorageOrgUnitID = so.FID \r\n");
/*1423*/        sql.append("left Join T_SCM_TransactionType tr on h.FTransactionTypeID = tr.FID \r\n");
/*1424*/        sql.append("INNER JOIN T_BD_MeasureUnit mu ON m.FBaseUnit = mu.FID \r\n");
/*1425*/        sql.append("LEFT JOIN T_BD_KAClassfication ka ON mcom.FKAClassID = ka.FID \r\n");
/*1427*/        return sql.toString();
            }

            private String sqlForMoveInOut(Context ctx, String headTbale, String entryTable, String SumTypeFieldName)
            {
/*1442*/        StringBuffer sql = new StringBuffer();
/*1443*/        sql.append(" From " + headTbale + " h \r\n");
/*1444*/        sql.append("INNER JOIN " + entryTable + " d ON h.FID = d.FParentID \r\n");
/*1445*/        sql.append("Inner Join T_BD_Material m On d.FMaterialID=m.FID \r\n");
/*1446*/        sql.append("INNER JOIN t_org_company fi ON d.FCompanyOrgUnitID = fi.FID \r\n");
/*1447*/        sql.append("INNER JOIN T_BD_MaterialCompanyInfo mcom On d.FMaterialID = mcom.FMaterialID  AND mcom.FCompanyID = d.FCompanyOrgUnitID \r\n");
/*1448*/        sql.append("inner join t_scm_transactiontype tr on tr.fid = h.ftransactiontypeid ");
/*1449*/        sql.append("left join t_scm_biztype bz on bz.fid = tr.fbiztypeid ");
/*1450*/        sql.append("Inner Join T_DB_WAREHOUSE wh on d.FWarehouseID = wh.FID \r\n");
/*1451*/        sql.append("Inner Join T_ORG_Storage so on d.FStorageOrgUnitID = so.FID \r\n");
/*1452*/        sql.append("INNER JOIN T_BD_MeasureUnit mu ON m.FBaseUnit = mu.FID \r\n");
/*1453*/        sql.append("LEFT JOIN T_BD_KAClassfication ka ON mcom.FKAClassID = ka.FID \r\n");
/*1454*/        return sql.toString();
            }

            private String getInsertNextPeriod(Context ctx, String tempTable, PeriodInfo currentPeriodInfo, PeriodInfo nextPeriodInfo)
                throws BOSException
            {
/*1469*/        StringBuffer sql = new StringBuffer();
/*1470*/        sql.append("insert into ").append(tempTable).append(" ").append("(FINDEX,FCompanyOrgUnitID,FCOMPANYNAME,FYear,FPeriod,FMaterialID,FMATERIALNAME,").append("FMaterialNumber,FSHORTNAME,FMaterialModel,FBASEUNITNAME,FSUMTYPEID,FSUMTYPENAME,FBEGINQTY,").append("FBEGINAMOUNT,FINQTY,FINAMOUNT,FOUTQTY,FOUTAMOUNT,FREMAINQTY,FREMAINAMOUNT) ").append("select a.FINDEX,a.FCompanyOrgUnitID,a.FCOMPANYNAME,").append(nextPeriodInfo.getPeriodYear()).append(" as FYear,").append(nextPeriodInfo.getPeriodNumber()).append(" as FPeriod,a.FMaterialID,a.FMATERIALNAME,").append("a.FMaterialNumber,a.FSHORTNAME,a.FMaterialModel,a.FBASEUNITNAME,a.FSUMTYPEID,a.FSUMTYPENAME,").append("0,0,0,0,0,0,0,0 ").append("from ").append(tempTable).append(" a ").append("left join ").append("(select fIndex,fmaterialid from ").append(tempTable).append(" t where ").append("t.fyear = ").append(nextPeriodInfo.getPeriodYear()).append(" ").append("and t.fperiod = ").append(nextPeriodInfo.getPeriodNumber()).append(" ").append(") b ").append("on a.fmaterialid = b.fmaterialid ").append("where ").append("a.fyear = ").append(currentPeriodInfo.getPeriodYear()).append(" ").append("and a.fperiod = ").append(currentPeriodInfo.getPeriodNumber()).append(" ").append("and b.fIndex is null");
/*1491*/        return sql.toString();
            }

            private String getPeriodHappenTotal(Context ctx, String tempTable, RptParams params)
                throws BOSException
            {
/*1504*/        StringBuffer sql = new StringBuffer();
/*1506*/        sql.append("Insert Into " + tempTable + "(FINDEX,FCompanyOrgUnitID,FCOMPANYNAME,FYear,FPeriod,FMaterialID ,FMATERIALNAME ,FMaterialNumber ,FSHORTNAME,FMaterialModel,FBASEUNITNAME,FSUMTYPEID ,FSUMTYPENAME ,FBEGINQTY ,FBEGINAMOUNT   ,FINQTY  ,FINAMOUNT ,FOUTQTY  ,FOUTAMOUNT ,FREMAINQTY ,FREMAINAMOUNT) \r\n");
/*1507*/        sql.append("Select 1,null,FCompanyName,FYear,FPeriod,null,null,null,null,null,null,FSUMTYPEID,FSumTypeName || '" + SCMUtils.getResource(res, "TOTAL", ctx) + "',");
/*1509*/        sql.append("sum(FBeginQty),sum(FBeginAmount),sum(FInQty),sum(FInAmount),sum(FOutQty),sum(FOutAmount),sum(FRemainQty),Sum(FRemainAmount) ");
/*1510*/        sql.append("From " + tempTable + " \r\n");
/*1511*/        sql.append("Group By FCompanyName,FYear,FPeriod,FSUMTYPEID,FSumTypeName");
/*1513*/        return sql.toString();
            }

            private String updatePeriodLast(Context ctx, String tempTable, int pYear, int pMonth)
                throws BOSException, EASBizException
            {
/*1529*/        StringBuffer sql = new StringBuffer();
/*1531*/        sql.append("Update " + tempTable + " Set FRemainQty=Isnull(FBeginQty,0)+Isnull(FInQty,0)-Isnull(FOutQty,0),");
/*1532*/        sql.append("FRemainAmount=Isnull(FBeginAmount,0)+Isnull(FInAmount,0)-Isnull(FOutAmount,0) \r\n");
/*1533*/        sql.append(" Where FYear=" + String.valueOf(pYear) + " And FPeriod=" + String.valueOf(pMonth) + "\r\n");
/*1534*/        return sql.toString();
            }

            private String updatePeriodFirst(Context ctx, String tempTable, int prePeriodY, int prePeriodM, int nextPeriodY, int nextPeriodM)
                throws BOSException, EASBizException
            {
/*1553*/        StringBuffer sql = new StringBuffer();
/*1555*/        sql.append("Update " + tempTable + " as t1 ");
/*1556*/        sql.append("Set(FBeginQty,FBeginAmount)=(");
/*1557*/        sql.append("\tselect t2.FRemainQty,t2.FRemainAmount ");
/*1558*/        sql.append("\tFrom " + tempTable + " t3 ");
/*1559*/        sql.append("\tLeft join  " + tempTable + " t2 ");
/*1560*/        sql.append("\tOn t3.Findex=t2.Findex ");
/*1561*/        sql.append(" \tand t3.FSumTypeName=t2.FSumTypeName ");
/*1562*/        sql.append("\tand t3.FMaterialID=t2.FMaterialID ");
/*1563*/        sql.append("\tWhere t3.FYear=" + nextPeriodY);
/*1564*/        sql.append(" \tAnd t3.Fperiod=" + nextPeriodM);
/*1565*/        sql.append(" \tAnd t2.FYear=" + prePeriodY);
/*1566*/        sql.append(" \tAnd t2.FPeriod=" + prePeriodM);
/*1567*/        sql.append(" \tAND T1.FINDEX = T2.FINDEX  ");
/*1568*/        sql.append("\tAND T1.FMATERIALID = T2.FMATERIALID ");
/*1569*/        sql.append("\tAND T1.FSUMTYPENAME = T2.FSUMTYPENAME)");
/*1570*/        sql.append("Where t1.FYear=" + nextPeriodY);
/*1571*/        sql.append(" And t1.Fperiod=" + nextPeriodM);
/*1572*/        return sql.toString();
            }

            private String getPeriodTotal(Context ctx, String tempTable, String SumTypeFieldName)
            {
/*1583*/        StringBuffer sql = new StringBuffer();
/*1584*/        sql.append("Insert Into " + tempTable + "(FINDEX,FCompanyOrgUnitID,FCOMPANYNAME,FYear,FPeriod,FMaterialID ,FMATERIALNAME ,FMaterialNumber ,FSHORTNAME,FMaterialModel,FBASEUNITNAME,FSUMTYPEID ,FSUMTYPENAME ,FBEGINQTY ,FBEGINAMOUNT   ,FINQTY  ,FINAMOUNT ,FOUTQTY  ,FOUTAMOUNT ,FREMAINQTY ,FREMAINAMOUNT)\r\n");
/*1585*/        sql.append(" Select 2 as FIndex,' ' as FCompanyOrgUnitID,' ' as FCompanyName,\r\n");
/*1586*/        sql.append("FYear,FPeriod,\r\n");
/*1587*/        sql.append("' ' as FMaterialID,' ' as FMaterialName,\r\n");
/*1588*/        sql.append("' ' as FMaterialNumber,' 'AS FSHORTNAME,' ' as FMaterialModel,");
/*1589*/        sql.append("' ' as FBaseUnitName,\r\n");
/*1590*/        if(SumTypeFieldName.equals("FCalculateType"))
/*1591*/            sql.append("0 as FSumTypeID, ");
/*1593*/        else
/*1593*/            sql.append("' ' as FSumTypeID, ");
/*1595*/        sql.append("'" + SCMUtils.getResource(res, "PERIODTOTAL", ctx) + "' FSumTypeName," + "\r\n");
/*1597*/        sql.append("sum(FBeginQty) as FBeginQty,sum(FBeginAmount) as FBeginAmount,\r\n");
/*1598*/        sql.append("sum(FInQty) as FInQty,Sum(FInAmount)as FInAmount,\r\n");
/*1599*/        sql.append("Sum(FOutQty) as FOutQty,Sum(FOutAmount) as FOutAmount,\r\n");
/*1600*/        sql.append("sum(FRemainQty) as FRemainQty,sum(FRemainAmount) as FRemainAmount \r\n");
/*1601*/        sql.append("From " + tempTable + "\r\n");
/*1602*/        sql.append("Where FIndex=1 \r\n");
/*1603*/        sql.append("Group By FYear,FPeriod \r\n");
/*1605*/        return sql.toString();
            }

            private void getYearTotal(Context ctx, String tempTable, int beginYear, int beginPeriod, int endYear, int endPeroid, String SumTypeFieldName)
                throws BOSException
            {
/*1624*/        StringBuffer sql = new StringBuffer();
/*1626*/        sql.append("Insert Into " + tempTable + " (FINDEX,FCompanyOrgUnitID,FCOMPANYNAME,FYear,FPeriod,FMaterialID ,FMATERIALNAME ,FMaterialNumber,FSHORTNAME ,FMaterialModel,FBASEUNITNAME,FSUMTYPEID ,FSUMTYPENAME ,FBEGINQTY ,FBEGINAMOUNT   ,FINQTY  ,FINAMOUNT ,FOUTQTY  ,FOUTAMOUNT ,FREMAINQTY ,FREMAINAMOUNT)\r\n");
/*1627*/        sql.append("Select 3 as FIndex,' ' as FCompanyOrgUnitID,' ' as FCompanyName,\r\n");
/*1628*/        sql.append("FYear, 0 as FPeriod, \r\n");
/*1629*/        sql.append("' ' as FMaterialID,' ' as FMaterialName, \r\n");
/*1630*/        sql.append("' ' as FMaterialNumber,' ' as FSHORTNAME ,' ' as FMaterialModel,");
/*1631*/        sql.append("' ' as FBaseUnitName, \r\n");
/*1632*/        if(SumTypeFieldName.equals("FCalculateType"))
/*1633*/            sql.append("0 as FSumTypeID, ");
/*1635*/        else
/*1635*/            sql.append("' ' as FSumTypeID, ");
/*1637*/        sql.append("'" + SCMUtils.getResource(res, "YEARTOTAL", ctx) + "' FSumTypeName," + "\r\n");
/*1639*/        sql.append("FBeginQty,FBeginAmount,\r\n");
/*1640*/        sql.append("0 as FInQty,0 as FInAmount,\r\n");
/*1641*/        sql.append("0 as FOutQty,0 as FOutAmount,\r\n");
/*1642*/        sql.append("0 as FRemainQty,0 as FRemainAmount \r\n");
/*1643*/        sql.append("From " + tempTable + "\r\n");
/*1644*/        sql.append("Where FIndex=2 And FYear=" + String.valueOf(beginYear) + " And FPeriod=" + String.valueOf(beginPeriod) + "\r\n");
/*1647*/        executeSQL(ctx, sql.toString());
/*1650*/        if(endYear > beginYear)
                {
/*1651*/            sql = new StringBuffer();
/*1652*/            sql.append("Insert Into " + tempTable + " (FINDEX,FCompanyOrgUnitID,FCOMPANYNAME,FYear,FPeriod,FMaterialID ,FMATERIALNAME ,FMaterialNumber ,FSHORTNAME,FMaterialModel,FBASEUNITNAME,FSUMTYPEID ,FSUMTYPENAME ,FBEGINQTY ,FBEGINAMOUNT   ,FINQTY  ,FINAMOUNT ,FOUTQTY  ,FOUTAMOUNT ,FREMAINQTY ,FREMAINAMOUNT)\r\n");
/*1653*/            sql.append("Select 3 as FIndex,' ' as FCompanyOrgUnitID,' ' as FCompanyName,\r\n");
/*1654*/            sql.append("FYear, 0 as FPeriod,\r\n");
/*1655*/            sql.append("' ' as FMaterialID,' ' as FMaterialName,\r\n");
/*1656*/            sql.append("' ' as FMaterialNumber,' ' AS FSHORTNAME,' ' as FMaterialModel,");
/*1657*/            sql.append("' ' as FBaseUnitName,\r\n");
/*1658*/            if(SumTypeFieldName.equals("FCalculateType"))
/*1659*/                sql.append("0 as FSumTypeID, ");
/*1661*/            else
/*1661*/                sql.append("' ' as FSumTypeID, ");
/*1663*/            sql.append("'" + SCMUtils.getResource(res, "YEARTOTAL", ctx) + "' FSumTypeName," + "\r\n");
/*1664*/            sql.append("FBeginQty,FBeginAmount,\r\n");
/*1665*/            sql.append("0 as FInQty,0 as FInAmount,\r\n");
/*1666*/            sql.append("0 as FOutQty,0 as FOutAmount,\r\n");
/*1667*/            sql.append("0 as FRemainQty,0 as FRemainAmount \r\n");
/*1668*/            sql.append("From " + tempTable + "\r\n");
/*1669*/            sql.append("Where FIndex=2 And FYear>" + String.valueOf(beginYear) + " And FPeriod=1" + "\r\n");
/*1670*/            executeSQL(ctx, sql.toString());
                }
/*1674*/        sql = new StringBuffer();
/*1675*/        sql.append("Update " + tempTable + " Set(FInQty,FInAmount,FOutQty,FOutAmount)=" + "\r\n");
/*1676*/        sql.append(" (Select FInTotalQty,FInTotalAmount,FOutTotalQty,FOutTotalAmount From \r\n");
/*1677*/        sql.append(" (Select FYear as FYear, \r\n");
/*1678*/        sql.append(" Sum(T1.FInQty) as FInTotalQty ,Sum(T1.FInAmount) as FInTotalAmount,\r\n");
/*1679*/        sql.append(" Sum(T1.FOutQty) as FOutTotalQty,Sum(T1.FOutAmount) as\t FOutTotalAmount\r\n");
/*1680*/        sql.append(" From " + tempTable + " T1 " + "\r\n");
/*1681*/        sql.append(" Where T1.FIndex=2 \r\n");
/*1682*/        sql.append(" Group By T1.FYear) as i \r\n");
/*1683*/        sql.append(" Where i.FYear = " + tempTable + ".FYear and " + tempTable + ".FIndex=3 )");
/*1684*/        executeSQL(ctx, sql.toString());
/*1687*/        sql = new StringBuffer();
/*1688*/        sql.append("Update " + tempTable + " Set ");
/*1689*/        sql.append("FRemainQty = isnull(FBeginQty,0)+isnull(FInQty,0)-isnull(FOutQty,0),");
/*1690*/        sql.append("FRemainAmount=isnull(FBeginAmount,0)+isnull(FInAmount,0)-isnull(FOutAmount,0) ");
/*1691*/        sql.append("Where FIndex=3  \r\n");
/*1692*/        executeSQL(ctx, sql.toString());
            }

            private void getAllTotal(Context ctx, String tempTable, int beginYear, int beginPeriod, String SumTypeFieldName)
                throws BOSException
            {
/*1708*/        StringBuffer sql = new StringBuffer();
/*1711*/        sql.append("Insert Into " + tempTable + " (FINDEX,FCompanyOrgUnitID,FCOMPANYNAME,FYear,FPeriod,FMaterialID ,FMATERIALNAME ,FMaterialNumber ,FSHORTNAME,FMaterialModel,FBASEUNITNAME,FSUMTYPEID ,FSUMTYPENAME ,FBEGINQTY ,FBEGINAMOUNT   ,FINQTY  ,FINAMOUNT ,FOUTQTY  ,FOUTAMOUNT ,FREMAINQTY ,FREMAINAMOUNT)\r\n");
/*1712*/        sql.append("Select 4 as FIndex,' ' as FCompanyOrgUnitID,' ' as FCompanyName,\r\n");
/*1713*/        sql.append("0 as FYear, 0 FPeriod,\r\n");
/*1714*/        sql.append("' ' as FMaterialID,' ' as FMaterialName,\r\n");
/*1715*/        sql.append("' ' as FMaterialNumber,' ' AS FSHORTNAME,' ' as FMaterialModel,");
/*1716*/        sql.append("' ' as FBaseUnitName,\r\n");
/*1717*/        if(SumTypeFieldName.equals("FCalculateType"))
/*1718*/            sql.append("0 as FSumTypeID, ");
/*1720*/        else
/*1720*/            sql.append("' ' as FSumTypeID, ");
/*1722*/        sql.append("'" + SCMUtils.getResource(res, "SUMALL", ctx) + "' FSumTypeName," + "\r\n");
/*1723*/        sql.append("FBeginQty,FBeginAmount,\r\n");
/*1724*/        sql.append("0 as FInQty,0 as FInAmount,\r\n");
/*1725*/        sql.append("0 as FOutQty,0 as FOutAmount,\r\n");
/*1726*/        sql.append("0 as FRemainQty,0 as FRemainAmount \r\n");
/*1727*/        sql.append("From " + tempTable + "\r\n");
/*1728*/        sql.append("Where FIndex=2 And FYear=" + String.valueOf(beginYear) + " And FPeriod=" + String.valueOf(beginPeriod) + "\r\n");
/*1731*/        executeSQL(ctx, sql.toString());
/*1733*/        sql.setLength(0);
/*1735*/        sql.append("Update " + tempTable + " AS T3 Set(FInQty,FInAmount,FOutQty,FOutAmount)=" + "\r\n");
/*1736*/        sql.append("    (Select FInTotalQty,FInTotalAmount,FOutTotalQty,FOutTotalAmount From \r\n");
/*1737*/        sql.append("       (Select Sum(T1.FInQty) as FInTotalQty ,Sum(T1.FInAmount) as FInTotalAmount, \r\n");
/*1738*/        sql.append("       Sum(T1.FOutQty) as FOutTotalQty,Sum(T1.FOutAmount) as FOutTotalAmount \r\n");
/*1739*/        sql.append("        From " + tempTable + " T1 " + "\r\n");
/*1740*/        sql.append("        Where T1.FIndex=3 )\r\n");
/*1741*/        sql.append("    i," + tempTable + " T2 " + "\r\n");
/*1742*/        sql.append("    Where T2.FIndex=4) Where T3.FIndex=4\r\n");
/*1743*/        executeSQL(ctx, sql.toString());
/*1747*/        sql.setLength(0);
/*1748*/        sql.append("Update " + tempTable + " Set ");
/*1749*/        sql.append("FRemainQty=isnull(FBeginQty,0)+isnull(FInQty,0)-isnull(FOutQty,0),");
/*1750*/        sql.append("FRemainAmount=isnull(FBeginAmount,0)+isnull(FInAmount,0)-isnull(FOutAmount,0) ");
/*1751*/        sql.append("Where FIndex=4 ");
/*1753*/        executeSQL(ctx, sql.toString());
            }

            protected RptParams _init(Context ctx, RptParams params)
                throws BOSException, EASBizException
            {
/*1758*/        return params;
            }

            protected RptParams _query(Context ctx, RptParams params, int from, int len)
                throws BOSException, EASBizException
            {
/*1770*/        String precisionSql = "select max(material.fpriceprecision),max(fqtyprecision) from t_bd_material material left join T_BD_MultiMeasureUnit unit on material.fid = unit.fmaterialId and material.fbaseUnit=unit.FMeasureUnitID where material.fid in (select fmaterialid from " + params.getString("tempTable") + ")";
/*1772*/        RptRowSet rsPrecision = executeQuery(precisionSql, null, ctx);
/*1773*/        int pricePrecision = 8;
/*1774*/        int qtyPrecision = 8;
/*1775*/        if(rsPrecision.next() && rsPrecision.getObject(0) != null && rsPrecision.getObject(1) != null)
                {
/*1777*/            pricePrecision = rsPrecision.getInt(0);
/*1778*/            qtyPrecision = rsPrecision.getInt(1);
                }
/*1782*/        CompanyOrgUnitInfo aCompanyOrgUnitInfo = (CompanyOrgUnitInfo)params.getObject("company");
/*1784*/        int amtPrecision = CalculateUtil.getLocalCurrencyPrecision(ctx, aCompanyOrgUnitInfo);
/*1787*/        RptParams pp = new RptParams();
/*1789*/        StringBuffer sql = new StringBuffer();
/*1790*/        sql.append("SELECT tmp.FCompanyName,tmp.FYear,tmp.FPeriod,");
/*1793*/        if(((SumTypeEnum)params.getObject("sumType")).getValue().equals("FMaterialGroupLevel"))
                {
/*1795*/            int materialGroupLevel = params.getInt("materialGroupLevel");
/*1796*/            for(int i = 1; i <= materialGroupLevel; i++)
/*1800*/                sql.append("tmp.FMATERIALGROUPNAME" + i + " ,");

                } else
                {
/*1804*/            sql.append("tmp.FSumTypeName,");
                }
/*1807*/        sql.append("tmp.FMaterialNumber,tmp.FMATERIALNAME,tmp.FSHORTNAME,tmp.FMaterialModel,tmp.FBASEUNITNAME,round(tmp.FBeginQTY,case when unit.fqtyprecision is null then " + qtyPrecision + " else unit.fqtyprecision end),");
/*1808*/        sql.append("( Case when isnull(tmp.FBeginQty,0)=0 then Null else round(to_decimal(tmp.FBeginAmount/tmp.FBeginQty, 21, 8), case when material.fpriceprecision is null then " + pricePrecision + " else material.fpriceprecision end) end) as FBeginPrice,");
/*1809*/        sql.append("round(tmp.FBeginAmount,").append(amtPrecision).append("),round(tmp.FInQTY,case when unit.fqtyprecision is null then " + qtyPrecision + " else unit.fqtyprecision end)," + "(Case when isnull(tmp.FInQty,0)=0 then Null else round(to_decimal(tmp.FInAmount/tmp.FInQty, 21, 8)," + "case when material.fpriceprecision is null then " + pricePrecision + " else material.fpriceprecision end) end) as FInPrice,");
/*1812*/        sql.append("round(tmp.FInAmount,").append(amtPrecision).append("),round(tmp.FOutQTY,case when unit.fqtyprecision is null then " + qtyPrecision + " else unit.fqtyprecision end)," + "(Case when isnull(tmp.FOutQty,0)=0 then Null else round(to_decimal(tmp.FOutAmount/tmp.FOutQty, 21, 8)," + "case when material.fpriceprecision is null then " + pricePrecision + " else material.fpriceprecision end) end) as FOutPrice,");
/*1815*/        sql.append("round(tmp.FOutAmount,").append(amtPrecision).append("),round(tmp.FRemainQTY,case when unit.fqtyprecision is null then " + qtyPrecision + " else unit.fqtyprecision end)," + "(Case when isnull(tmp.FRemainQty,0)=0 then Null else round(to_decimal(tmp.FRemainAmount/tmp.FRemainQty, 21, 8)," + "case when material.fpriceprecision is null then " + pricePrecision + " else material.fpriceprecision end) end) as FRemainPrice,");
/*1818*/        sql.append("round(tmp.FRemainAmount,").append(amtPrecision).append("),tmp.FSumTypeID,tmp.FMaterialID,tmp.FIndex,tmp.FCompanyOrgUnitID,case when unit.fqtyprecision is null then " + qtyPrecision + " else unit.fqtyprecision end as fqtyprecision," + "case when material.fpriceprecision is null then " + pricePrecision + " else material.fpriceprecision end as fpriceprecision FROM " + params.getString("tempTable") + " as tmp ");
/*1820*/        sql.append("left join t_bd_material material on tmp.fmaterialid = material.fid left join T_BD_MultiMeasureUnit unit on material.fid = unit.fmaterialId and material.fbaseUnit=unit.FMeasureUnitID ");
/*1822*/        if(params.getBoolean("onlyViewSumRow"))
/*1823*/            sql.append(" Where tmp.Findex<>0 ");
/*1827*/        if(from == 0)
                {
/*1828*/            String countSql = "select count(*) from " + params.getString("tempTable");
/*1829*/            if(params.getBoolean("onlyViewSumRow"))
/*1830*/                countSql = countSql + " Where Findex<>0 ";
/*1832*/            RptRowSet rsCount = executeQuery(countSql, null, ctx);
/*1833*/            rsCount.next();
/*1834*/            int count = rsCount.getInt(0);
/*1835*/            pp.setInt("totalCount", count);
                }
/*1840*/        String SumTypeFieldName = null;
/*1841*/        if(params.getObject("sumType") != null)
                {
/*1842*/            SumTypeFieldName = ((SumTypeEnum)params.getObject("sumType")).getValue().toString();
/*1844*/            if(SumTypeFieldName.equals("FCalculateType"))
/*1845*/                sql.append(" Order By isnull(tmp.FYear,2099) ,isnull(tmp.FPeriod,99),isnull(tmp.FSUMTYPEID,9),tmp.FIndex,tmp.FMaterialNumber ");
/*1847*/            else
/*1847*/            if(((SumTypeEnum)params.getObject("sumType")).getValue().equals("FMaterialGroupLevel"))
                    {
/*1849*/                int materialGroupLevel = params.getInt("materialGroupLevel");
/*1850*/                sql.append(" Order By isnull(tmp.FYear,2099) ,isnull(tmp.FPeriod,99)");
/*1851*/                for(int i = 1; i <= materialGroupLevel; i++)
/*1853*/                    sql.append(",tmp.FMATERIALGROUPID" + i + ",tmp.FMATERIALGROUPNAME" + i);

/*1856*/                sql.append(",tmp.FIndex");
                    } else
                    {
/*1860*/                sql.append(" Order By isnull(tmp.FYear,2099) ,isnull(tmp.FPeriod,99),isnull(tmp.FSUMTYPEID,'zzzzzzzzzz'),tmp.FIndex,tmp.FMaterialNumber ");
                    }
                }
/*1864*/        RptRowSet rs = executeQuery(sql.toString(), null, from, len, ctx);
/*1866*/        pp.setObject("rowset", rs);
/*1869*/        return pp;
            }

            private void executeSQL(Context ctx, String sql)
                throws BOSException
            {
/*1873*/        if(sql != null && sql.trim().length() > 0)
/*1874*/            executeUpdate(sql, null, ctx);
            }

            private static Logger logger = Logger.getLogger("com.kingdee.eas.scm.cal.app.StockGatherReportFacadeControllerBean");
            private String res;
            public static final String newline = "\r\n";

}


/*
	DECOMPILATION REPORT

	Decompiled from: E:\kingdee\myworkpace\myproj\lib\server\eas\scm_cal-server.jar
	Total time: 9672 ms
	Jad reported messages/errors:
	Exit status: 0
	Caught exceptions:
*/